doctrine / cache

Doctrine Cache component

Home Page:https://www.doctrine-project.org/projects/cache.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ChainCache calls protected methods on injected cache instances

gskema opened this issue · comments

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.

  1. Why was it done this way?
  2. Should we add final keyword to public methods of CacheProvider?
  3. Is ChainCache the only class that does this?
  4. Is there anything to be done about it?

Closing as we're sunsetting this library. Please see #354 for more details.