Rack::Cache::EntityStore::Disk

Stores entity bodies on disk at the specified path.

Attributes

root[R]

Path where entities should be stored. This directory is created the first time the store is instansiated if it does not already exist.

Public Class Methods

new(root) click to toggle source
    # File lib/rack/cache/entitystore.rb, line 90
90:       def initialize(root)
91:         @root = root
92:         FileUtils.mkdir_p root, :mode => 0755
93:       end

Protected Class Methods

resolve(uri) click to toggle source
     # File lib/rack/cache/entitystore.rb, line 162
162:       def self.resolve(uri)
163:         path = File.expand_path(uri.opaque || uri.path)
164:         new path
165:       end

Public Instance Methods

exist?(key) click to toggle source
    # File lib/rack/cache/entitystore.rb, line 95
95:       def exist?(key)
96:         File.exist?(body_path(key))
97:       end
open(key) click to toggle source

Open the entity body and return an IO object. The IO object’s each method is overridden to read 8K chunks instead of lines.

     # File lib/rack/cache/entitystore.rb, line 116
116:       def open(key)
117:         Body.open(body_path(key), 'rb')
118:       rescue Errno::ENOENT
119:         nil
120:       end
purge(key) click to toggle source
     # File lib/rack/cache/entitystore.rb, line 140
140:       def purge(key)
141:         File.unlink body_path(key)
142:         nil
143:       rescue Errno::ENOENT
144:         nil
145:       end
read(key) click to toggle source
     # File lib/rack/cache/entitystore.rb, line 99
 99:       def read(key)
100:         File.open(body_path(key), 'rb') { |f| f.read }
101:       rescue Errno::ENOENT
102:         nil
103:       end
write(body, ttl=nil) click to toggle source
     # File lib/rack/cache/entitystore.rb, line 122
122:       def write(body, ttl=nil)
123:         filename = ['buf', $$, Thread.current.object_id].join('-')
124:         temp_file = storage_path(filename)
125:         key, size =
126:           File.open(temp_file, 'wb') { |dest|
127:             slurp(body) { |part| dest.write(part) }
128:           }
129: 
130:         path = body_path(key)
131:         if File.exist?(path)
132:           File.unlink temp_file
133:         else
134:           FileUtils.mkdir_p File.dirname(path), :mode => 0755
135:           FileUtils.mv temp_file, path
136:         end
137:         [key, size]
138:       end

Protected Instance Methods

body_path(key) click to toggle source
     # File lib/rack/cache/entitystore.rb, line 158
158:       def body_path(key)
159:         storage_path spread(key)
160:       end
spread(key) click to toggle source
     # File lib/rack/cache/entitystore.rb, line 152
152:       def spread(key)
153:         key = key.dup
154:         key[2,0] = '/'
155:         key
156:       end
storage_path(stem) click to toggle source
     # File lib/rack/cache/entitystore.rb, line 148
148:       def storage_path(stem)
149:         File.join root, stem
150:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.