Skip to content

Commit

Permalink
Add support for prefixed cache (#51)
Browse files Browse the repository at this point in the history
* Add support for prefixed cache

* Fixed issue with requiring service to be an object
  • Loading branch information
iainmckay authored and Nyholm committed Mar 28, 2017
1 parent c3d344c commit bdaae57
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
41 changes: 41 additions & 0 deletions src/Factory/PrefixedFactory.php
@@ -0,0 +1,41 @@
<?php

/*
* This file is part of php-cache organization.
*
* (c) 2015-2015 Aaron Scherer <aequasi@gmail.com>, Tobias Nyholm <tobias.nyholm@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Cache\AdapterBundle\Factory;

use Cache\Prefixed\PrefixedCachePool;
use Symfony\Component\OptionsResolver\OptionsResolver;

class PrefixedFactory extends AbstractAdapterFactory
{
protected static $dependencies = [
['requiredClass' => 'Cache\Prefixed\PrefixedCachePool', 'packageName' => 'cache/prefixed-cache'],
];

/**
* {@inheritdoc}
*/
public function getAdapter(array $config)
{
return new PrefixedCachePool($config['service'], $config['prefix']);
}

/**
* {@inheritdoc}
*/
protected static function configureOptionResolver(OptionsResolver $resolver)
{
parent::configureOptionResolver($resolver);

$resolver->setRequired(['prefix', 'service']);
$resolver->setAllowedTypes('prefix', ['string']);
}
}
3 changes: 2 additions & 1 deletion src/Resources/config/services.yml
Expand Up @@ -15,6 +15,8 @@ services:
class: Cache\AdapterBundle\Factory\MemcacheFactory
cache.factory.predis:
class: Cache\AdapterBundle\Factory\PredisFactory
cache.factory.prefixed:
class: Cache\AdapterBundle\Factory\PrefixedFactory
cache.factory.redis:
class: Cache\AdapterBundle\Factory\RedisFactory
cache.factory.void:
Expand Down Expand Up @@ -44,4 +46,3 @@ services:
class: Cache\AdapterBundle\Factory\DoctrineXcacheFactory
cache.factory.doctrine_zenddata:
class: Cache\AdapterBundle\Factory\DoctrineZendDataFactory

0 comments on commit bdaae57

Please sign in to comment.