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 241 def initialize(root="/tmp/rack-cache/meta-#{ARGV[0]}") 242 @root = File.expand_path(root) 243 FileUtils.mkdir_p(root, :mode => 0755) 244 end
resolve(uri)
click to toggle source
# File lib/rack/cache/meta_store.rb 284 def self.resolve(uri) 285 path = File.expand_path(uri.opaque || uri.path) 286 new path 287 end
Public Instance Methods
purge(key)
click to toggle source
# File lib/rack/cache/meta_store.rb 264 def purge(key) 265 path = key_path(key) 266 File.unlink(path) 267 nil 268 rescue Errno::ENOENT, IOError 269 nil 270 end
read(key)
click to toggle source
# File lib/rack/cache/meta_store.rb 246 def read(key) 247 path = key_path(key) 248 File.open(path, 'rb') { |io| Marshal.load(io) } 249 rescue Errno::ENOENT, IOError 250 [] 251 end
write(key, entries, ttl = nil)
click to toggle source
# File lib/rack/cache/meta_store.rb 253 def write(key, entries, ttl = nil) 254 tries = 0 255 begin 256 path = key_path(key) 257 File.open(path, 'wb') { |io| Marshal.dump(entries, io, -1) } 258 rescue Errno::ENOENT, IOError 259 Dir.mkdir(File.dirname(path), 0755) 260 retry if (tries += 1) == 1 261 end 262 end
Private Instance Methods
key_path(key)
click to toggle source
# File lib/rack/cache/meta_store.rb 273 def key_path(key) 274 File.join(root, spread(hexdigest(key))) 275 end
spread(sha, n=2)
click to toggle source
# File lib/rack/cache/meta_store.rb 277 def spread(sha, n=2) 278 sha = sha.dup 279 sha[n,0] = '/' 280 sha 281 end