Stores entity bodies on the heap using a Hash object.
Public class methods
new
(hash={})
Create the store with the specified backing Hash.
[show source]
# File lib/rack/cache/entitystore.rb, line 38 38: def initialize(hash={}) 39: @hash = hash 40: end
resolve
(uri)
[show source]
# File lib/rack/cache/entitystore.rb, line 74 74: def self.resolve(uri) 75: new 76: end
Public instance methods
exist?
(key)
Determine whether the response body with the specified key (SHA1) exists in the store.
[show source]
# File lib/rack/cache/entitystore.rb, line 44 44: def exist?(key) 45: @hash.include?(key) 46: end
open
(key)
Return an object suitable for use as a Rack response body for the specified key.
[show source]
# File lib/rack/cache/entitystore.rb, line 50 50: def open(key) 51: (body = @hash[key]) && body.dup 52: end
purge
(key)
Remove the body corresponding to key; return nil.
[show source]
# File lib/rack/cache/entitystore.rb, line 69 69: def purge(key) 70: @hash.delete(key) 71: nil 72: end
read
(key)
Read all data associated with the given key and return as a single String.
[show source]
# File lib/rack/cache/entitystore.rb, line 56 56: def read(key) 57: (body = @hash[key]) && body.join 58: end
write
(body)
Write the Rack response body immediately and return the SHA1 key.
[show source]
# File lib/rack/cache/entitystore.rb, line 61 61: def write(body) 62: buf = [] 63: key, size = slurp(body) { |part| buf << part } 64: @hash[key] = buf 65: [key, size] 66: end