Class Rack::Cache::MetaStore::Disk

  1. lib/rack/cache/metastore.rb

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

Methods

public class

  1. new
  2. resolve

public instance

  1. purge
  2. read
  3. write

Attributes

root [R]

Public class methods

new (root="/tmp/rack-cache/meta-
[show 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
resolve (uri)
[show 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

purge (key)
[show 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
read (key)
[show 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
write (key, entries)
[show 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