Skip to content

Commit

Permalink
feature #18176 [Cache] Restrict flushes to namespace scopes (nicolas-…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
fabpot committed Mar 15, 2016
2 parents ded8491 + 8744443 commit f29d46f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Symfony/Component/Cache/Adapter/ApcuAdapter.php
Expand Up @@ -50,7 +50,9 @@ protected function doHave($id)
*/
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();
}

/**
Expand Down
9 changes: 7 additions & 2 deletions src/Symfony/Component/Cache/Adapter/DoctrineAdapter.php
Expand Up @@ -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);
}

/**
Expand All @@ -47,7 +48,11 @@ protected function doHave($id)
*/
protected function doClear($namespace)
{
return $this->provider->flushAll();
$namespace = $this->provider->getNamespace();

return isset($namespace[0])
? $this->provider->deleteAll()
: $this->provider->flushAll();
}

/**
Expand Down

0 comments on commit f29d46f

Please sign in to comment.