Closed amatriain closed 8 years ago
prefer using memcached or similar so garbage data is no problem ...
how about using an entity store that always returns ['']
and never stores anything -> no new code needed ?
I'm not sure what you mean. Implementing a new backend for this behavior, so that configuration would look like this instead?
require 'rack/cache'
use Rack::Cache,
:metastore => 'file:/var/cache/rack/meta',
:entitystore => 'dummy://',
:verbose => true
run app
It would require more or less as much code as this PR, I'm not sure what you mean by no new code needed.
A separate backend would mean the code handling the response is less complex and all other users (99.9%+) don't have to pay the price of the extra if/else checks. It will also be a good example of how to deal with special usecases without having to modify the core library :)
That's very different from the code in this PR, even if it achieves the same result. I'm going to open a different PR, see if you like that one better.
This PR adds the ability to set rack-cache entity store to nil, e.g.:
When
entitystore
is set to nil, rack-cache doesn't persist response bodies. If a cached response is still fresh, or if it's stale but found to be still valid, rack-cache returns only the response headers with an empty body. The code performing the request should check if the response comes from the cache (e.g. checking theX-Rack-Cache
header) and in in this case ignore the response body.Obviously this is only useful for use cases in which, if a cached response is still valid, its body is not interesting.
This is useful for my particular use case but may be interesting for other people. In particular this avoids the common problem of the backend (disk in my case) filling up with old entities, because rack-cache performs no cleanup of old useless entities once there is a new response. This can be avoided with this PR by not persisting entries in the backend in the first place.