Class: Hpreserve::AbstractCacher
- Inherits:
-
Object
- Object
- Hpreserve::AbstractCacher
- Defined in:
- lib/hpreserve/abstract_cacher.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#patterns ⇒ Object
Returns the value of attribute patterns.
-
#storage ⇒ Object
Returns the value of attribute storage.
Instance Method Summary collapse
- #expire(pattern) ⇒ Object
-
#initialize(patterns) ⇒ AbstractCacher
constructor
A new instance of AbstractCacher.
- #match?(variable) ⇒ Boolean
-
#retrieve(key) ⇒ Object
overwrite these in your ConcreteCacher to do use whatever you use.
- #store(key, value) ⇒ Object
Constructor Details
#initialize(patterns) ⇒ AbstractCacher
Returns a new instance of AbstractCacher.
6 7 8 |
# File 'lib/hpreserve/abstract_cacher.rb', line 6 def initialize(patterns) self.patterns = patterns end |
Instance Attribute Details
#patterns ⇒ Object
Returns the value of attribute patterns.
4 5 6 |
# File 'lib/hpreserve/abstract_cacher.rb', line 4 def patterns @patterns end |
#storage ⇒ Object
Returns the value of attribute storage.
4 5 6 |
# File 'lib/hpreserve/abstract_cacher.rb', line 4 def storage @storage end |
Instance Method Details
#expire(pattern) ⇒ Object
29 30 31 32 |
# File 'lib/hpreserve/abstract_cacher.rb', line 29 def expire(pattern) @storage ||= {} storage.delete_if {|key, value| key.match(pattern) } end |
#match?(variable) ⇒ Boolean
10 11 12 13 14 |
# File 'lib/hpreserve/abstract_cacher.rb', line 10 def match?(variable) pattern = patterns.detect {|p| variable.match(p[:match]) } return nil unless pattern variable.gsub(pattern[:match], pattern[:key]) end |
#retrieve(key) ⇒ Object
overwrite these in your ConcreteCacher to do use whatever you use
19 20 21 22 |
# File 'lib/hpreserve/abstract_cacher.rb', line 19 def retrieve(key) @storage ||= {} storage[key] end |
#store(key, value) ⇒ Object
24 25 26 27 |
# File 'lib/hpreserve/abstract_cacher.rb', line 24 def store(key, value) @storage ||= {} storage[key] = value end |