Class: Ro::Cache
- Inherits:
-
Map
- Object
- Map
- Ro::Cache
- Defined in:
- lib/ro/cache.rb
Instance Method Summary collapse
Instance Method Details
#invalidate(key) ⇒ Object
21 22 23 24 |
# File 'lib/ro/cache.rb', line 21 def invalidate(key) prefix = Array(key).dup.tap{|array| array.pop} set(prefix, {}) end |
#read(key, &block) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ro/cache.rb', line 8 def read(key, &block) if has?(key) get(key) else if block value = block.call write(key, value) else nil end end end |
#write(key, value) ⇒ Object
3 4 5 6 |
# File 'lib/ro/cache.rb', line 3 def write(key, value) invalidate(key) set(key => value) end |