Class | Rack::Cache::MetaStore::Disk |
In: |
lib/rack/cache/metastore.rb
|
Parent: | MetaStore |
Concrete MetaStore implementation that stores request/response pairs on disk.
root | [R] |
# File lib/rack/cache/metastore.rb, line 212 212: def initialize(root="/tmp/rack-cache/meta-#{ARGV[0]}") 213: @root = File.expand_path(root) 214: FileUtils.mkdir_p(root, :mode => 0755) 215: end
# File lib/rack/cache/metastore.rb, line 255 255: def self.resolve(uri) 256: path = File.expand_path(uri.opaque || uri.path) 257: new path 258: end
# File lib/rack/cache/metastore.rb, line 235 235: def purge(key) 236: path = key_path(key) 237: File.unlink(path) 238: nil 239: rescue Errno::ENOENT, IOError 240: nil 241: end
# File lib/rack/cache/metastore.rb, line 217 217: def read(key) 218: path = key_path(key) 219: File.open(path, 'rb') { |io| Marshal.load(io) } 220: rescue Errno::ENOENT, IOError 221: [] 222: end
# File lib/rack/cache/metastore.rb, line 224 224: def write(key, entries) 225: tries = 0 226: begin 227: path = key_path(key) 228: File.open(path, 'wb') { |io| Marshal.dump(entries, io, -1) } 229: rescue Errno::ENOENT, IOError 230: Dir.mkdir(File.dirname(path), 0755) 231: retry if (tries += 1) == 1 232: end 233: end