Class: CustomCache::ScopeCache
- Inherits:
-
Base
- Object
- Base
- CustomCache::ScopeCache
show all
- Defined in:
- lib/custom_cache/scope_cache.rb
Constant Summary
Constants inherited
from Base
Base::DEFAULT_EXPIRY
Instance Method Summary
collapse
Instance Method Details
#cached_content ⇒ Object
5
6
7
|
# File 'lib/custom_cache/scope_cache.rb', line 5
def cached_content
Rails.cache.read(self.scope) || {}
end
|
#clear ⇒ Object
23
24
25
|
# File 'lib/custom_cache/scope_cache.rb', line 23
def clear
Rails.cache.delete(scope) if scope.present?
end
|
#read(key) ⇒ Object
9
10
11
12
13
|
# File 'lib/custom_cache/scope_cache.rb', line 9
def read(key)
if scope.present? && key.present?
cached_content[key] if cached_content.present?
end
end
|
#write(key, content, options = {}) ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/custom_cache/scope_cache.rb', line 15
def write(key, content, options = {})
if scope.present? && content.present?
cached_content.merge!(key => content)
Rails.cache.write(scope, cached_content.merge!(key => content),
expires_in: (options[:expires_in] || DEFAULT_EXPIRY))
end
end
|