class Rack::Cache::EntityStore
Entity stores are used to cache response bodies across requests. All Implementations are required to calculate a SHA checksum of the data written which becomes the response body’s key.
Constants
- DISK
-
Stores entity bodies on disk at the specified path.
- FILE
-
Stores entity bodies on disk at the specified path.
- GAE
- GAECACHE
- HEAP
-
Stores entity bodies on the heap using a Hash object.
- MEM
-
Stores entity bodies on the heap using a Hash object.
- MEMCACHE
- MEMCACHED
- NOOP
-
Noop
Entity Store backend.Set ‘entitystore` to ’noop:/‘. Does not persist response bodies (no disk/memory used). Responses from the cache will have an empty body. Clients must ignore these empty cached response (check for x-rack-cache response header). Atm cannot handle streamed responses, patch needed.
Private Instance Methods
Source
# File lib/rack/cache/entity_store.rb 26 def bytesize(string); string.bytesize; end
Source
# File lib/rack/cache/entity_store.rb 14 def slurp(body) 15 digest, size = Digest::SHA1.new, 0 16 body.each do |part| 17 size += bytesize(part) 18 digest << part 19 yield part 20 end 21 body.close if body.respond_to? :close 22 [digest.hexdigest, size] 23 end
Read body calculating the SHA1 checksum and size while yielding each chunk to the block. If the body responds to close, call it after iteration is complete. Return a two-tuple of the form: [ hexdigest, size ].