feature #18176 [Cache] Restrict flushes to namespace scopes (nicolas-grekas)

This PR was merged into the 3.1-dev branch.

Discussion
----------

[Cache] Restrict flushes to namespace scopes

| Q             | A
| ------------- | ---
| Branch        | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | no
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Instead of flushing all cache namespaces all the time, we can flush only the keys in the namespace.

Commits
-------

8744443 [Cache] Restrict flushes to namespace scopes
This commit is contained in:
Fabien Potencier 2016-03-15 17:54:37 +01:00
commit f29d46f29b
2 changed files with 10 additions and 3 deletions

View File

@ -50,7 +50,9 @@ class ApcuAdapter extends AbstractAdapter
*/
protected function doClear($namespace)
{
return apcu_clear_cache();
return isset($namespace[0]) && class_exists('APCuIterator', false)
? apcu_delete(new \APCuIterator(sprintf('/^%s/', preg_quote($namespace, '/')), APC_ITER_KEY))
: apcu_clear_cache();
}
/**

View File

@ -22,8 +22,9 @@ class DoctrineAdapter extends AbstractAdapter
public function __construct(CacheProvider $provider, $defaultLifetime = 0, $namespace = '')
{
parent::__construct($namespace, $defaultLifetime);
parent::__construct('', $defaultLifetime);
$this->provider = $provider;
$provider->setNamespace($namespace);
}
/**
@ -47,7 +48,11 @@ class DoctrineAdapter extends AbstractAdapter
*/
protected function doClear($namespace)
{
return $this->provider->flushAll();
$namespace = $this->provider->getNamespace();
return isset($namespace[0])
? $this->provider->deleteAll()
: $this->provider->flushAll();
}
/**