Class: Rack::Cache::EntityStore::Moneta
- Inherits:
-
Rack::Cache::EntityStore
- Object
- Rack::Cache::EntityStore
- Rack::Cache::EntityStore::Moneta
- Extended by:
- MonetaResolver
- Defined in:
- lib/rack/cache/moneta.rb
Constant Summary
Constants inherited from Rack::Cache::EntityStore
Instance Method Summary collapse
- #exist?(key) ⇒ Boolean
-
#initialize(cache) ⇒ Moneta
constructor
A new instance of Moneta.
- #open(key) ⇒ Object
- #purge(key) ⇒ Object
- #read(key) ⇒ Object
- #write(body, ttl = 0) ⇒ Object
Methods included from MonetaResolver
Constructor Details
#initialize(cache) ⇒ Moneta
Returns a new instance of Moneta.
67 68 69 |
# File 'lib/rack/cache/moneta.rb', line 67 def initialize(cache) @cache = cache end |
Instance Method Details
#exist?(key) ⇒ Boolean
76 77 78 |
# File 'lib/rack/cache/moneta.rb', line 76 def exist?(key) @cache.key?(key) end |
#open(key) ⇒ Object
71 72 73 74 |
# File 'lib/rack/cache/moneta.rb', line 71 def open(key) data = read(key) data && [data] end |
#purge(key) ⇒ Object
91 92 93 94 |
# File 'lib/rack/cache/moneta.rb', line 91 def purge(key) @cache.delete(key) nil end |
#read(key) ⇒ Object
80 81 82 |
# File 'lib/rack/cache/moneta.rb', line 80 def read(key) @cache[key] end |
#write(body, ttl = 0) ⇒ Object
84 85 86 87 88 89 |
# File 'lib/rack/cache/moneta.rb', line 84 def write(body, ttl = 0) buf = StringIO.new key, size = slurp(body) { |part| buf.write(part) } @cache.store(key, buf.string, ttl == 0 ? {} : { expires: ttl }) [key, size] end |