Class: ActiveFacets::DocumentCache

Inherits:
Object
  • Object
show all
Defined in:
lib/active_facets/document_cache.rb

Constant Summary collapse

CACHE_PREFIX =
'af_doc_cache'

Class Method Summary collapse

Class Method Details

.fetch(facade, options = {}) ⇒ Object

Fetches a JSON document representing the facade

Parameters:

  • facade (Object)

    to cache

  • options (Hash) (defaults to: {})

    for Rails.cache.fetch

  • &block (Proc)

    for cache miss

Returns:

  • (Object)


12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/active_facets/document_cache.rb', line 12

def self.fetch(facade, options = {})
  return yield unless cacheable?(facade)

  force = facade.opts[ActiveFacets.cache_force_key] || options[:force] || ActiveFacets::default_cache_options[:force]
  cache_key = digest_key(facade)
  if force || !(result = Rails.cache.fetch(cache_key))
    result = yield
    Rails.cache.write(cache_key, ::Oj.dump(result), ActiveFacets::default_cache_options.merge(options).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

Parameters:

  • facade (Object)

    to cache

  • options (Hash) (defaults to: {})

    for Rails.cache.fetch

  • &block (Proc)

    for cache miss

Returns:

  • (Object)


31
32
33
34
# File 'lib/active_facets/document_cache.rb', line 31

def self.fetch_association(facade, association, options = {})
  #TODO --jdc implement
  yield
end