Skip to content

Commit 96cf968

Browse files
julien-maitanNyholm
authored andcommitted
Add support for namespaced cache (#50)
Add support for namespaced cache
1 parent bdaae57 commit 96cf968

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/Factory/ArrayFactory.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Cache\AdapterBundle\Factory;
1313

1414
use Cache\Adapter\PHPArray\ArrayCachePool;
15+
use Cache\Namespaced\NamespacedCachePool;
16+
use Symfony\Component\OptionsResolver\OptionsResolver;
1517

1618
/**
1719
* @author Tobias Nyholm <[email protected]>
@@ -27,6 +29,28 @@ class ArrayFactory extends AbstractAdapterFactory
2729
*/
2830
public function getAdapter(array $config)
2931
{
30-
return new ArrayCachePool();
32+
$pool = new ArrayCachePool();
33+
34+
if (null !== $config['pool_namespace']) {
35+
$pool = new NamespacedCachePool($pool, $config['pool_namespace']);
36+
}
37+
38+
return $pool;
39+
}
40+
41+
/**
42+
* {@inheritdoc}
43+
*/
44+
protected static function configureOptionResolver(OptionsResolver $resolver)
45+
{
46+
parent::configureOptionResolver($resolver);
47+
48+
$resolver->setDefaults(
49+
[
50+
'pool_namespace' => null,
51+
]
52+
);
53+
54+
$resolver->setAllowedTypes('pool_namespace', ['string', 'null']);
3155
}
3256
}

0 commit comments

Comments
 (0)