cache-plugin icon indicating copy to clipboard operation
cache-plugin copied to clipboard

The cache should validate that found items were actually created by it / meant for it

Open naderman opened this issue 8 years ago • 10 comments

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.

naderman avatar Oct 14 '16 12:10 naderman

Another possible solution would be to treat that cache data as invalid/empty and overwrite it if needed.

Nyholm avatar Oct 14 '16 12:10 Nyholm

That'd be fine with me too, but may lead to two separate systems continuously overwriting the value

naderman avatar Oct 14 '16 12:10 naderman

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.

Nyholm avatar Oct 14 '16 12:10 Nyholm

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.

dbu avatar Oct 15 '16 11:10 dbu

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.

sagikazarmark avatar Oct 15 '16 13:10 sagikazarmark

IMO it should just fail hard and throw an exception. It's clearly a configuration mistake that needs to be fixed.

kelunik avatar Nov 13 '17 08:11 kelunik

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.

dbu avatar Nov 13 '17 09:11 dbu

In that case throw a warning each time and ignore the cache. It ought to be fixed.

kelunik avatar Nov 13 '17 09:11 kelunik

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.

dbu avatar Nov 13 '17 09:11 dbu

That's a good point, indeed. :+1:

kelunik avatar Nov 13 '17 09:11 kelunik