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 209
209:       def initialize(root="/tmp/rack-cache/meta-#{ARGV[0]}")
210:         @root = File.expand_path(root)
211:         FileUtils.mkdir_p(root, :mode => 0755)
212:       end

[Source]

     # File lib/rack/cache/metastore.rb, line 252
252:       def self.resolve(uri)
253:         path = File.expand_path(uri.opaque || uri.path)
254:         new path
255:       end

Public Instance methods

[Source]

     # File lib/rack/cache/metastore.rb, line 232
232:       def purge(key)
233:         path = key_path(key)
234:         File.unlink(path)
235:         nil
236:       rescue Errno::ENOENT, IOError
237:         nil
238:       end

[Source]

     # File lib/rack/cache/metastore.rb, line 214
214:       def read(key)
215:         path = key_path(key)
216:         File.open(path, 'rb') { |io| Marshal.load(io) }
217:       rescue Errno::ENOENT, IOError
218:         []
219:       end

[Source]

     # File lib/rack/cache/metastore.rb, line 221
221:       def write(key, entries)
222:         tries = 0
223:         begin
224:           path = key_path(key)
225:           File.open(path, 'wb') { |io| Marshal.dump(entries, io, -1) }
226:         rescue Errno::ENOENT, IOError
227:           Dir.mkdir(File.dirname(path), 0755)
228:           retry if (tries += 1) == 1
229:         end
230:       end

[Validate]