Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f29d46f

Browse files
committed
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
2 parents ded8491 + 8744443 commit f29d46f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/Symfony/Component/Cache/Adapter/ApcuAdapter.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ protected function doHave($id)
5050
*/
5151
protected function doClear($namespace)
5252
{
53-
return apcu_clear_cache();
53+
return isset($namespace[0]) && class_exists('APCuIterator', false)
54+
? apcu_delete(new \APCuIterator(sprintf('/^%s/', preg_quote($namespace, '/')), APC_ITER_KEY))
55+
: apcu_clear_cache();
5456
}
5557

5658
/**

src/Symfony/Component/Cache/Adapter/DoctrineAdapter.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ class DoctrineAdapter extends AbstractAdapter
2222

2323
public function __construct(CacheProvider $provider, $defaultLifetime = 0, $namespace = '')
2424
{
25-
parent::__construct($namespace, $defaultLifetime);
25+
parent::__construct('', $defaultLifetime);
2626
$this->provider = $provider;
27+
$provider->setNamespace($namespace);
2728
}
2829

2930
/**
@@ -47,7 +48,11 @@ protected function doHave($id)
4748
*/
4849
protected function doClear($namespace)
4950
{
50-
return $this->provider->flushAll();
51+
$namespace = $this->provider->getNamespace();
52+
53+
return isset($namespace[0])
54+
? $this->provider->deleteAll()
55+
: $this->provider->flushAll();
5156
}
5257

5358
/**

0 commit comments

Comments
 (0)