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.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/active_remote/cached/cache.rb', line 10

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.



8
9
10
# File 'lib/active_remote/cached/cache.rb', line 8

def cache_provider
  @cache_provider
end

Instance Method Details

#delete(*args) ⇒ Object



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

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

#enable_nested_caching!Object



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

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

#exist?(*args) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/active_remote/cached/cache.rb', line 32

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

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



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

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

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

  fetch_value
end

#read(*args) ⇒ Object



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

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

#write(*args) ⇒ Object



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

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