class Rack::Cache::MetaStore::DISK
Concrete MetaStore
implementation that stores request/response pairs on disk.
Attributes
Public Class Methods
Source
# File lib/rack/cache/meta_store.rb 240 def initialize(root="/tmp/rack-cache/meta-#{ARGV[0]}") 241 @root = File.expand_path(root) 242 FileUtils.mkdir_p(root, :mode => 0755) 243 end
Source
# File lib/rack/cache/meta_store.rb 283 def self.resolve(uri) 284 path = File.expand_path(uri.opaque || uri.path) 285 new path 286 end
Public Instance Methods
Source
# File lib/rack/cache/meta_store.rb 263 def purge(key) 264 path = key_path(key) 265 File.unlink(path) 266 nil 267 rescue Errno::ENOENT, IOError 268 nil 269 end
Source
# File lib/rack/cache/meta_store.rb 245 def read(key) 246 path = key_path(key) 247 File.open(path, 'rb') { |io| Marshal.load(io) } 248 rescue Errno::ENOENT, IOError 249 [] 250 end
Source
# File lib/rack/cache/meta_store.rb 252 def write(key, entries, ttl = nil) 253 tries = 0 254 begin 255 path = key_path(key) 256 File.open(path, 'wb') { |io| Marshal.dump(entries, io, -1) } 257 rescue Errno::ENOENT, IOError 258 Dir.mkdir(File.dirname(path), 0755) 259 retry if (tries += 1) == 1 260 end 261 end
Private Instance Methods
Source
# File lib/rack/cache/meta_store.rb 272 def key_path(key) 273 File.join(root, spread(hexdigest(key))) 274 end
Source
# File lib/rack/cache/meta_store.rb 276 def spread(sha, n=2) 277 sha = sha.dup 278 sha[n,0] = '/' 279 sha 280 end