File: query_cache.rb

package info (click to toggle)
ruby-otr-activerecord 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 340 kB
  • sloc: ruby: 562; sh: 133; makefile: 6
file content (21 lines) | stat: -rw-r--r-- 509 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module OTR
  module ActiveRecord
    #
    # Rack middleware to enable ActiveRecord's query cache for each request.
    #
    class QueryCache
      def initialize(app)
        @app = app
      end

      def call(env)
        state = nil
        cache = defined?(::ActiveRecord::QueryCache::ExecutorHooks) ? ::ActiveRecord::QueryCache::ExecutorHooks : ::ActiveRecord::QueryCache
        state = cache.run
        @app.call(env)
      ensure
        cache.complete(state) if state
      end
    end
  end
end