Class: ActiveRemote::Cached::Cache
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- ActiveRemote::Cached::Cache
show all
- Defined in:
- lib/active_remote/cached/cache.rb
Defined Under Namespace
Classes: InvalidCacheProvider
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(new_cache_provider) ⇒ Cache
Returns a new instance of Cache.
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/active_remote/cached/cache.rb', line 14
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_provider ⇒ Object
Returns the value of attribute cache_provider.
12
13
14
|
# File 'lib/active_remote/cached/cache.rb', line 12
def cache_provider
@cache_provider
end
|
Instance Method Details
#delete(*args) ⇒ Object
27
28
29
30
|
# File 'lib/active_remote/cached/cache.rb', line 27
def delete(*args)
nested_cache_provider.delete(*args)
super
end
|
#enable_nested_caching! ⇒ Object
32
33
34
|
# File 'lib/active_remote/cached/cache.rb', line 32
def enable_nested_caching!
@nested_cache_provider = ::ActiveSupport::Cache::MemoryStore.new
end
|
#exist?(*args) ⇒ Boolean
40
41
42
|
# File 'lib/active_remote/cached/cache.rb', line 40
def exist?(*args)
nested_cache_provider.exist?(*args) || super
end
|
#fetch(name, options = {}) ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'lib/active_remote/cached/cache.rb', line 44
def fetch(name, options = {})
provider_options = provider_fetch_options(options)
fetch_value = nested_cache_provider.fetch(name, provider_options) { super(name, provider_options) }
delete(name) if delete_after_fetch?(fetch_value, options, provider_options)
fetch_value
end
|
#nested_caching? ⇒ Boolean
36
37
38
|
# File 'lib/active_remote/cached/cache.rb', line 36
def nested_caching?
!nested_cache_provider.is_a?(::ActiveSupport::Cache::NullStore)
end
|
#read(*args) ⇒ Object
53
54
55
|
# File 'lib/active_remote/cached/cache.rb', line 53
def read(*args)
nested_cache_provider.read(*args) || super
end
|
#write(*args) ⇒ Object
57
58
59
60
|
# File 'lib/active_remote/cached/cache.rb', line 57
def write(*args)
nested_cache_provider.write(*args)
super
end
|