Module: Goodyear::QueryCache

Included in:
QueryMethods
Defined in:
lib/goodyear/query_cache.rb

Instance Method Summary collapse

Instance Method Details

#cache_query(query) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/goodyear/query_cache.rb', line 8

def cache_query(query)
  cache_key = sha(query)
  Goodyear.force_cache
  result = if store.exist?(cache_key) && Goodyear.force_cache
      ActiveSupport::Notifications.instrument "cache.query.elasticsearch", name: self.name, query: query
      store.fetch cache_key
    else
      res = []
      ActiveSupport::Notifications.instrument "query.elasticsearch", name: self.name, query: query do
        res = yield
      end
      store.write(cache_key, res) if Goodyear.force_cache
      res
    end
  result.dup
end

#storeObject



4
5
6
# File 'lib/goodyear/query_cache.rb', line 4

def store
 @query_cache ||= setup_store!
end