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, 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
Constructor Details
#initialize(root = "/tmp/rack-cache/meta-#{ARGV[0]}") ⇒ Disk
Returns a new instance of Disk.
173 174 175 176 |
# File 'lib/rack/cache/metastore.rb', line 173 def initialize(root="/tmp/rack-cache/meta-#{ARGV[0]}") @root = File.(root) FileUtils.mkdir_p(root, :mode => 0755) end |
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
171 172 173 |
# File 'lib/rack/cache/metastore.rb', line 171 def root @root end |
Class Method Details
.resolve(uri) ⇒ Object
213 214 215 216 |
# File 'lib/rack/cache/metastore.rb', line 213 def self.resolve(uri) path = File.(uri.opaque || uri.path) new path end |
Instance Method Details
#purge(key) ⇒ Object
193 194 195 196 197 198 199 |
# File 'lib/rack/cache/metastore.rb', line 193 def purge(key) path = key_path(key) File.unlink(path) nil rescue Errno::ENOENT nil end |
#read(key) ⇒ Object
178 179 180 181 182 183 |
# File 'lib/rack/cache/metastore.rb', line 178 def read(key) path = key_path(key) File.open(path, 'rb') { |io| Marshal.load(io) } rescue Errno::ENOENT [] end |
#write(key, entries) ⇒ Object
185 186 187 188 189 190 191 |
# File 'lib/rack/cache/metastore.rb', line 185 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 |