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