Class: Rack::Client::Cache::EntityStore::Heap
- Inherits:
-
Rack::Client::Cache::EntityStore
- Object
- Rack::Client::Cache::EntityStore
- Rack::Client::Cache::EntityStore::Heap
- Defined in:
- lib/rack/client/middleware/cache/entitystore.rb
Constant Summary
Constants inherited from Rack::Client::Cache::EntityStore
Class Method Summary collapse
Instance Method Summary collapse
-
#exist?(key) ⇒ Boolean
Determine whether the response body with the specified key (SHA1) exists in the store.
-
#initialize(hash = {}) ⇒ Heap
constructor
Create the store with the specified backing Hash.
-
#open(key) ⇒ Object
Return an object suitable for use as a Rack response body for the specified key.
-
#purge(key) ⇒ Object
Remove the body corresponding to key; return nil.
-
#read(key) ⇒ Object
Read all data associated with the given key and return as a single String.
-
#write(body) ⇒ Object
Write the Rack response body immediately and return the SHA1 key.
Constructor Details
#initialize(hash = {}) ⇒ Heap
Create the store with the specified backing Hash.
31 32 33 |
# File 'lib/rack/client/middleware/cache/entitystore.rb', line 31 def initialize(hash={}) @hash = hash end |
Class Method Details
.resolve(uri) ⇒ Object
67 68 69 |
# File 'lib/rack/client/middleware/cache/entitystore.rb', line 67 def self.resolve(uri) new end |
Instance Method Details
#exist?(key) ⇒ Boolean
Determine whether the response body with the specified key (SHA1) exists in the store.
37 38 39 |
# File 'lib/rack/client/middleware/cache/entitystore.rb', line 37 def exist?(key) @hash.include?(key) end |
#open(key) ⇒ Object
Return an object suitable for use as a Rack response body for the specified key.
43 44 45 |
# File 'lib/rack/client/middleware/cache/entitystore.rb', line 43 def open(key) (body = @hash[key]) && body.dup end |
#purge(key) ⇒ Object
Remove the body corresponding to key; return nil.
62 63 64 65 |
# File 'lib/rack/client/middleware/cache/entitystore.rb', line 62 def purge(key) @hash.delete(key) nil end |
#read(key) ⇒ Object
Read all data associated with the given key and return as a single String.
49 50 51 |
# File 'lib/rack/client/middleware/cache/entitystore.rb', line 49 def read(key) (body = @hash[key]) && body.join end |
#write(body) ⇒ Object
Write the Rack response body immediately and return the SHA1 key.
54 55 56 57 58 59 |
# File 'lib/rack/client/middleware/cache/entitystore.rb', line 54 def write(body) buf = [] key, size = slurp(body) { |part| buf << part } @hash[key] = buf [key, size] end |