Class: Rack::Cache::EntityStore::Moneta

Inherits:
Rack::Cache::EntityStore show all
Extended by:
MonetaResolver
Defined in:
lib/rack/cache/moneta.rb

Constant Summary

Constants inherited from Rack::Cache::EntityStore

MONETA

Instance Method Summary collapse

Methods included from MonetaResolver

resolve

Constructor Details

#initialize(cache) ⇒ Moneta

Returns a new instance of Moneta.



68
69
70
# File 'lib/rack/cache/moneta.rb', line 68

def initialize(cache)
  @cache = cache
end

Instance Method Details

#exist?(key) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/rack/cache/moneta.rb', line 77

def exist?(key)
  @cache.key?(key)
end

#open(key) ⇒ Object



72
73
74
75
# File 'lib/rack/cache/moneta.rb', line 72

def open(key)
  data = read(key)
  data && [data]
end

#purge(key) ⇒ Object



92
93
94
95
# File 'lib/rack/cache/moneta.rb', line 92

def purge(key)
  @cache.delete(key)
  nil
end

#read(key) ⇒ Object



81
82
83
# File 'lib/rack/cache/moneta.rb', line 81

def read(key)
  @cache[key]
end

#write(body, ttl = 0) ⇒ Object



85
86
87
88
89
90
# File 'lib/rack/cache/moneta.rb', line 85

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