Class: ActiveRemote::Cached::Cache

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/active_remote/cached/cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(new_cache_provider) ⇒ Cache

Returns a new instance of Cache.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/active_remote/cached/cache.rb', line 7

def initialize(new_cache_provider)
  @cache_provider = new_cache_provider
  @nested_cache_provider = ::ActiveSupport::Cache::NullStore.new

  validate_provider_method_present(:delete)
  validate_provider_method_present(:exist?)
  validate_provider_method_present(:fetch)
  validate_provider_method_present(:read)
  validate_provider_method_present(:write)

  super(@cache_provider)
end

Instance Attribute Details

#cache_providerObject (readonly)

Returns the value of attribute cache_provider.



5
6
7
# File 'lib/active_remote/cached/cache.rb', line 5

def cache_provider
  @cache_provider
end

Instance Method Details

#delete(*args) ⇒ Object



20
21
22
23
# File 'lib/active_remote/cached/cache.rb', line 20

def delete(*args)
  nested_cache_provider.delete(*args)
  super
end

#enable_nested_caching!Object



25
26
27
# File 'lib/active_remote/cached/cache.rb', line 25

def enable_nested_caching!
  @nested_cache_provider = ::ActiveSupport::Cache::MemoryStore.new
end

#exist?(*args) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/active_remote/cached/cache.rb', line 29

def exist?(*args)
  nested_cache_provider.exist?(*args) || super
end

#fetch(name, options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/active_remote/cached/cache.rb', line 33

def fetch(name, options = {})
  fetch_value = nested_cache_provider.fetch(name, options) { super }

  unless valid_fetched_value?(fetch_value, options)
    delete(name)
  end

  return fetch_value
end

#read(*args) ⇒ Object



43
44
45
# File 'lib/active_remote/cached/cache.rb', line 43

def read(*args)
  nested_cache_provider.read(*args) || super
end

#write(*args) ⇒ Object



47
48
49
50
# File 'lib/active_remote/cached/cache.rb', line 47

def write(*args)
  nested_cache_provider.write(*args)
  super
end