Class: Rack::Cache::MetaStore::Disk
- Inherits:
-
Rack::Cache::MetaStore
- Object
- Rack::Cache::MetaStore
- Rack::Cache::MetaStore::Disk
- Defined in:
- lib/rack/cache/metastore.rb
Overview
Concrete MetaStore implementation that stores request/response pairs on disk.
Constant Summary
Constants inherited from Rack::Cache::MetaStore
DISK, FILE, GAE, GAECACHE, HEAP, MEM, MEMCACHE, MEMCACHED
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(root = "/tmp/rack-cache/meta-#{ARGV[0]}") ⇒ Disk
constructor
A new instance of Disk.
- #purge(key) ⇒ Object
- #read(key) ⇒ Object
- #write(key, entries) ⇒ Object
Methods inherited from Rack::Cache::MetaStore
#cache_key, #invalidate, #lookup, #store
Constructor Details
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
207 208 209 |
# File 'lib/rack/cache/metastore.rb', line 207 def root @root end |
Class Method Details
.resolve(uri) ⇒ Object
249 250 251 252 |
# File 'lib/rack/cache/metastore.rb', line 249 def self.resolve(uri) path = File.(uri.opaque || uri.path) new path end |
Instance Method Details
#purge(key) ⇒ Object
229 230 231 232 233 234 235 |
# File 'lib/rack/cache/metastore.rb', line 229 def purge(key) path = key_path(key) File.unlink(path) nil rescue Errno::ENOENT nil end |
#read(key) ⇒ Object
214 215 216 217 218 219 |
# File 'lib/rack/cache/metastore.rb', line 214 def read(key) path = key_path(key) File.open(path, 'rb') { |io| Marshal.load(io) } rescue Errno::ENOENT [] end |
#write(key, entries) ⇒ Object
221 222 223 224 225 226 227 |
# File 'lib/rack/cache/metastore.rb', line 221 def write(key, entries) path = key_path(key) File.open(path, 'wb') { |io| Marshal.dump(entries, io, -1) } rescue Errno::ENOENT Dir.mkdir(File.dirname(path), 0755) retry end |