class Rack::Cache::MetaStore::Disk
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 227 def initialize(root="/tmp/rack-cache/meta-#{ARGV[0]}") 228 @root = File.expand_path(root) 229 FileUtils.mkdir_p(root, :mode => 0755) 230 end
resolve(uri)
click to toggle source
# File lib/rack/cache/meta_store.rb 270 def self.resolve(uri) 271 path = File.expand_path(uri.opaque || uri.path) 272 new path 273 end
Public Instance Methods
purge(key)
click to toggle source
# File lib/rack/cache/meta_store.rb 250 def purge(key) 251 path = key_path(key) 252 File.unlink(path) 253 nil 254 rescue Errno::ENOENT, IOError 255 nil 256 end
read(key)
click to toggle source
# File lib/rack/cache/meta_store.rb 232 def read(key) 233 path = key_path(key) 234 File.open(path, 'rb') { |io| Marshal.load(io) } 235 rescue Errno::ENOENT, IOError 236 [] 237 end
write(key, entries)
click to toggle source
# File lib/rack/cache/meta_store.rb 239 def write(key, entries) 240 tries = 0 241 begin 242 path = key_path(key) 243 File.open(path, 'wb') { |io| Marshal.dump(entries, io, -1) } 244 rescue Errno::ENOENT, IOError 245 Dir.mkdir(File.dirname(path), 0755) 246 retry if (tries += 1) == 1 247 end 248 end
Private Instance Methods
key_path(key)
click to toggle source
# File lib/rack/cache/meta_store.rb 259 def key_path(key) 260 File.join(root, spread(hexdigest(key))) 261 end
spread(sha, n=2)
click to toggle source
# File lib/rack/cache/meta_store.rb 263 def spread(sha, n=2) 264 sha = sha.dup 265 sha[n,0] = '/' 266 sha 267 end