Skip to content

Commit bdaae57

Browse files
iainmckayNyholm
authored andcommitted
Add support for prefixed cache (#51)
* Add support for prefixed cache * Fixed issue with requiring service to be an object
1 parent c3d344c commit bdaae57

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

src/Factory/PrefixedFactory.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-cache organization.
5+
*
6+
* (c) 2015-2015 Aaron Scherer <aequasi@gmail.com>, Tobias Nyholm <tobias.nyholm@gmail.com>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Cache\AdapterBundle\Factory;
13+
14+
use Cache\Prefixed\PrefixedCachePool;
15+
use Symfony\Component\OptionsResolver\OptionsResolver;
16+
17+
class PrefixedFactory extends AbstractAdapterFactory
18+
{
19+
protected static $dependencies = [
20+
['requiredClass' => 'Cache\Prefixed\PrefixedCachePool', 'packageName' => 'cache/prefixed-cache'],
21+
];
22+
23+
/**
24+
* {@inheritdoc}
25+
*/
26+
public function getAdapter(array $config)
27+
{
28+
return new PrefixedCachePool($config['service'], $config['prefix']);
29+
}
30+
31+
/**
32+
* {@inheritdoc}
33+
*/
34+
protected static function configureOptionResolver(OptionsResolver $resolver)
35+
{
36+
parent::configureOptionResolver($resolver);
37+
38+
$resolver->setRequired(['prefix', 'service']);
39+
$resolver->setAllowedTypes('prefix', ['string']);
40+
}
41+
}

src/Resources/config/services.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ services:
1515
class: Cache\AdapterBundle\Factory\MemcacheFactory
1616
cache.factory.predis:
1717
class: Cache\AdapterBundle\Factory\PredisFactory
18+
cache.factory.prefixed:
19+
class: Cache\AdapterBundle\Factory\PrefixedFactory
1820
cache.factory.redis:
1921
class: Cache\AdapterBundle\Factory\RedisFactory
2022
cache.factory.void:
@@ -44,4 +46,3 @@ services:
4446
class: Cache\AdapterBundle\Factory\DoctrineXcacheFactory
4547
cache.factory.doctrine_zenddata:
4648
class: Cache\AdapterBundle\Factory\DoctrineZendDataFactory
47-

0 commit comments

Comments
 (0)