ChainCache calls protected methods on injected cache instances
gskema opened this issue · comments
Gytis Šk. commented
Let's say I want to have a ProxyCache
class, which looks something like this:
class ProxyCache extends CacheProvider
{
// A) Incorrect way to extend
public function contains($id)
{
return $this->getCache()->contains($id);
}
// B) Correct way to extend
public function doContains($id)
{
return $this->getCache()->doContains($id);
}
...
}
My colleagues extended contains()
method and left doContains()
empty because it looks like it will never be called. Later I added throw new Exception('should not be called')
to doContains
and found that ChainCache
actually call protected methods on injected cache instances. This is very misleading and left use with a non-working cache for X period of time.
- Why was it done this way?
- Should we add
final
keyword to public methods ofCacheProvider
? - Is ChainCache the only class that does this?
- Is there anything to be done about it?
Andreas Braun commented
Closing as we're sunsetting this library. Please see #354 for more details.