Class: ActiveFacet::DocumentCache
- Inherits:
-
Object
- Object
- ActiveFacet::DocumentCache
- Defined in:
- lib/active_facet/document_cache.rb
Constant Summary collapse
- CACHE_PREFIX =
'af_doc_cache'
Class Method Summary collapse
-
.fetch(facade, options = {}) ⇒ Object
Fetches a JSON document representing the facade.
-
.fetch_association(facade, association, options = {}) ⇒ Object
Fetches a JSON document representing the association specified for the resource in the facade.
Class Method Details
.fetch(facade, options = {}) ⇒ Object
Fetches a JSON document representing the facade
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/active_facet/document_cache.rb', line 12 def self.fetch(facade, = {}) return yield unless cacheable?(facade) force = facade.opts[ActiveFacet.cache_force_key] || [:force] || ActiveFacet::[:force] cache_key = digest_key(facade) if force || !(result = Rails.cache.fetch(cache_key)) result = yield Rails.cache.write(cache_key, ::Oj.dump(result), ActiveFacet::.merge().merge(force: force)) result else ::Oj.load(result) end end |
.fetch_association(facade, association, options = {}) ⇒ Object
Fetches a JSON document representing the association specified for the resource in the facade
31 32 33 34 |
# File 'lib/active_facet/document_cache.rb', line 31 def self.fetch_association(facade, association, = {}) # override and implement yield end |