Class: EarthTools::Cache
- Inherits:
-
Object
- Object
- EarthTools::Cache
- Defined in:
- lib/earth_tools/cache.rb
Overview
The Earth Tools cache wrapper.
Must respond to: -> [] – read -> []= – write -> del – delete -> keys – list of keys
Instance Method Summary collapse
-
#[](url) ⇒ Object
Read from the cache.
-
#[]=(url, value) ⇒ Object
Write to the cache.
-
#expire(url) ⇒ Object
Delete cache entry for given URL, or pass
:all
to clear all URLs. -
#initialize(store, prefix) ⇒ Cache
constructor
A new instance of Cache.
Constructor Details
#initialize(store, prefix) ⇒ Cache
Returns a new instance of Cache.
16 17 18 19 |
# File 'lib/earth_tools/cache.rb', line 16 def initialize(store, prefix) @store = store @prefix = prefix end |
Instance Method Details
#[](url) ⇒ Object
Read from the cache.
24 25 26 |
# File 'lib/earth_tools/cache.rb', line 24 def [](url) @store[key_for(url)] end |
#[]=(url, value) ⇒ Object
Write to the cache.
30 31 32 |
# File 'lib/earth_tools/cache.rb', line 30 def []=(url, value) @store[key_for(url)] = value end |
#expire(url) ⇒ Object
Delete cache entry for given URL, or pass :all
to clear all URLs.
37 38 39 40 41 42 43 |
# File 'lib/earth_tools/cache.rb', line 37 def expire(url) if url == :all urls.each{ |u| expire(u) } else @store.send(@store.respond_to?(:del) ? :del : :delete, key_for(url)) end end |