cache-plugin
cache-plugin copied to clipboard
The cache should validate that found items were actually created by it / meant for it
Q | A |
---|---|
Bug? | yes |
New Feature? | no |
Version |
Actual Behavior
The cache uses any item matching the key and may error if the content does not match what it expects.
Expected Behavior / Possible Solution
The cache should treat an item that was potentially created by another service with a colliding key as a reason to skip caching the resource with this key.
Another possible solution would be to treat that cache data as invalid/empty and overwrite it if needed.
That'd be fine with me too, but may lead to two separate systems continuously overwriting the value
Yeah. That is why one would need the PrefixedCache https://github.com/php-cache/cache/pull/96 =)
If we do not overwrite we risk that random garbage data from an other service blocks this cache key forever. That would mean that we never can cache.
i would vote that we implement overwriting then. if you use a different cache instance per service you can already use different paths, and ifnot the PR @Nyholm did will further improve the situation. still, data on a disk could be corrupted for whatever reason (incomplete write, actual disk failure, other types of "this should never happens" errors) so stopping to cache sounds wrong.
I think overwriting should be the way to go.
@naderman cache libraries and cache systems usually support namespacing, so avoiding collision is the responsibility of the user to configure it IMO.
IMO it should just fail hard and throw an exception. It's clearly a configuration mistake that needs to be fixed.
its an error, yes, but in production mode you rather want things to survive than a hard exception. it can log an error, or if it can know we are in some sort of dev mode, it can throw an exception.
In that case throw a warning each time and ignore the cache. It ought to be fixed.
yeah agree, trigger a warning level error sounds like the right thing to do.
ignoring the cache in that case could lead to cache stop working at some point down the road if it either got corrupted by a random filesystem accident, or a hard crash mid-writing to the cache, or because we changed the format (maybe by accident, or in a new major version). thus i think overwriting should be ok in that case.
That's a good point, indeed. :+1: