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-#{ARGV[0]}") click to toggle 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
resolve(uri) click to toggle 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

purge(key) click to toggle 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
read(key) click to toggle 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
write(key, entries) click to toggle 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

Private Instance Methods

key_path(key) click to toggle source
     # File lib/rack/cache/metastore.rb, line 248
248:       def key_path(key)
249:         File.join(root, spread(hexdigest(key)))
250:       end
spread(sha, n=2) click to toggle source
     # File lib/rack/cache/metastore.rb, line 252
252:       def spread(sha, n=2)
253:         sha = sha.dup
254:         sha[n,0] = '/'
255:         sha
256:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.