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