class Rack::Cache::MetaStore::FILE
Concrete MetaStore implementation that stores request/response pairs on disk.
Attributes
Public Class Methods
Source
# File lib/rack/cache/meta_store.rb, line 239 def initialize(root="/tmp/rack-cache/meta-#{ARGV[0]}") @root = File.expand_path(root) FileUtils.mkdir_p(root, :mode => 0755) end
Source
# File lib/rack/cache/meta_store.rb, line 282 def self.resolve(uri) path = File.expand_path(uri.opaque || uri.path) new path end
Public Instance Methods
Source
# File lib/rack/cache/meta_store.rb, line 262 def purge(key) path = key_path(key) File.unlink(path) nil rescue Errno::ENOENT, IOError nil end
Source
# File lib/rack/cache/meta_store.rb, line 244 def read(key) path = key_path(key) File.open(path, 'rb') { |io| Marshal.load(io) } rescue Errno::ENOENT, IOError [] end
Source
# File lib/rack/cache/meta_store.rb, line 251 def write(key, entries, ttl = nil) 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