Class Rack::Cache::MetaStore::Disk
In: lib/rack/cache/metastore.rb
Parent: MetaStore

Concrete MetaStore implementation that stores request/response pairs on disk.

Methods

new   purge   read   resolve   write  

Attributes

root  [R] 

Public Class methods

[Source]

     # File lib/rack/cache/metastore.rb, line 216
216:       def initialize(root="/tmp/rack-cache/meta-#{ARGV[0]}")
217:         @root = File.expand_path(root)
218:         FileUtils.mkdir_p(root, :mode => 0755)
219:       end

[Source]

     # File lib/rack/cache/metastore.rb, line 259
259:       def self.resolve(uri)
260:         path = File.expand_path(uri.opaque || uri.path)
261:         new path
262:       end

Public Instance methods

[Source]

     # File lib/rack/cache/metastore.rb, line 239
239:       def purge(key)
240:         path = key_path(key)
241:         File.unlink(path)
242:         nil
243:       rescue Errno::ENOENT, IOError
244:         nil
245:       end

[Source]

     # File lib/rack/cache/metastore.rb, line 221
221:       def read(key)
222:         path = key_path(key)
223:         File.open(path, 'rb') { |io| Marshal.load(io) }
224:       rescue Errno::ENOENT, IOError
225:         []
226:       end

[Source]

     # File lib/rack/cache/metastore.rb, line 228
228:       def write(key, entries)
229:         tries = 0
230:         begin
231:           path = key_path(key)
232:           File.open(path, 'wb') { |io| Marshal.dump(entries, io, -1) }
233:         rescue Errno::ENOENT, IOError
234:           Dir.mkdir(File.dirname(path), 0755)
235:           retry if (tries += 1) == 1
236:         end
237:       end

[Validate]