class Rack::Cache::MetaStore::FILE
Concrete MetaStore implementation that stores request/response pairs on disk.
Attributes
root[R]
Public Class Methods
new(root="/tmp/rack-cache/meta-
click to toggle source
# File lib/rack/cache/meta_store.rb, line 227 def initialize(root="/tmp/rack-cache/meta-#{ARGV[0]}") @root = File.expand_path(root) FileUtils.mkdir_p(root, :mode => 0755) end
resolve(uri)
click to toggle source
# File lib/rack/cache/meta_store.rb, line 270 def self.resolve(uri) path = File.expand_path(uri.opaque || uri.path) new path end
Public Instance Methods
purge(key)
click to toggle source
# File lib/rack/cache/meta_store.rb, line 250 def purge(key) path = key_path(key) File.unlink(path) nil rescue Errno::ENOENT, IOError nil end
read(key)
click to toggle source
# File lib/rack/cache/meta_store.rb, line 232 def read(key) path = key_path(key) File.open(path, 'rb') { |io| Marshal.load(io) } rescue Errno::ENOENT, IOError [] end
write(key, entries)
click to toggle source
# File lib/rack/cache/meta_store.rb, line 239 def write(key, entries) tries = 0 begin path = key_path(key) File.open(path, 'wb') { |io| Marshal.dump(entries, io, -1) } rescue Errno::ENOENT, IOError Dir.mkdir(File.dirname(path), 0755) retry if (tries += 1) == 1 end end
Private Instance Methods
key_path(key)
click to toggle source
# File lib/rack/cache/meta_store.rb, line 259 def key_path(key) File.join(root, spread(hexdigest(key))) end
spread(sha, n=2)
click to toggle source
# File lib/rack/cache/meta_store.rb, line 263 def spread(sha, n=2) sha = sha.dup sha[n,0] = '/' sha end