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