Skip to content

Commit

Permalink
Added support for namespaced cache (#46)
Browse files Browse the repository at this point in the history
* Added support for namespaced cache

* Applied fixes from StyleCI (#47)

* Added change log
  • Loading branch information
Nyholm authored Aug 7, 2016
1 parent e97ee76 commit 775dabc
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 12 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee

## UNRELEASED

## 0.3.5

### Added

* `ConnectException` that is thrown when you fail to connect to Redis
* Support for using the `NamespacedCachePool`

### Fixed

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"php": "^5.5 || ^7.0",
"symfony/framework-bundle": "^2.7 || ^3.0",
"symfony/options-resolver": "^2.7 || ^3.0",
"psr/cache": "^1.0"
"psr/cache": "^1.0",
"cache/namespaced-cache": "^0.1"
},
"require-dev": {
"phpunit/phpunit": "5.0.* || ^4.0",
Expand Down
17 changes: 13 additions & 4 deletions src/Factory/MemcachedFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Cache\Adapter\Memcached\MemcachedCachePool;
use Cache\AdapterBundle\ProviderHelper\Memcached;
use Cache\Namespaced\NamespacedCachePool;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
Expand All @@ -32,7 +33,13 @@ public function getAdapter(array $config)
$client = new Memcached($config['persistent_id']);
$client->addServer($config['host'], $config['port']);

return new MemcachedCachePool($client);
$pool = new MemcachedCachePool($client);

if (null !== $config['pool_namespace']) {
$pool = new NamespacedCachePool($pool, $config['pool_namespace']);
}

return $pool;
}

/**
Expand All @@ -41,13 +48,15 @@ public function getAdapter(array $config)
protected static function configureOptionResolver(OptionsResolver $resolver)
{
$resolver->setDefaults([
'persistent_id' => null,
'host' => '127.0.0.1',
'port' => 11211,
'persistent_id' => null,
'host' => '127.0.0.1',
'port' => 11211,
'pool_namespace' => null,
]);

$resolver->setAllowedTypes('persistent_id', ['string', 'null']);
$resolver->setAllowedTypes('host', ['string']);
$resolver->setAllowedTypes('port', ['string', 'int']);
$resolver->setAllowedTypes('pool_namespace', ['string', 'null']);
}
}
17 changes: 13 additions & 4 deletions src/Factory/PredisFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Cache\AdapterBundle\Factory;

use Cache\Adapter\Predis\PredisCachePool;
use Cache\Namespaced\NamespacedCachePool;
use Predis\Client;
use Symfony\Component\OptionsResolver\OptionsResolver;

Expand Down Expand Up @@ -43,7 +44,13 @@ public function getAdapter(array $config)
$client = new Client($dsn->getDsn());
}

return new PredisCachePool($client);
$pool = new PredisCachePool($client);

if (null !== $config['pool_namespace']) {
$pool = new NamespacedCachePool($pool, $config['pool_namespace']);
}

return $pool;
}

/**
Expand All @@ -55,14 +62,16 @@ protected static function configureOptionResolver(OptionsResolver $resolver)

$resolver->setDefaults(
[
'host' => '127.0.0.1',
'port' => '6379',
'scheme' => 'tcp',
'host' => '127.0.0.1',
'port' => '6379',
'scheme' => 'tcp',
'pool_namespace' => null,
]
);

$resolver->setAllowedTypes('host', ['string']);
$resolver->setAllowedTypes('port', ['string', 'int']);
$resolver->setAllowedTypes('scheme', ['string']);
$resolver->setAllowedTypes('pool_namespace', ['string', 'null']);
}
}
15 changes: 12 additions & 3 deletions src/Factory/RedisFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Cache\Adapter\Redis\RedisCachePool;
use Cache\AdapterBundle\Exception\ConnectException;
use Cache\Namespaced\NamespacedCachePool;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
Expand Down Expand Up @@ -55,7 +56,13 @@ public function getAdapter(array $config)
}
}

return new RedisCachePool($client);
$pool = new RedisCachePool($client);

if (null !== $config['pool_namespace']) {
$pool = new NamespacedCachePool($pool, $config['pool_namespace']);
}

return $pool;
}

/**
Expand All @@ -67,12 +74,14 @@ protected static function configureOptionResolver(OptionsResolver $resolver)

$resolver->setDefaults(
[
'host' => '127.0.0.1',
'port' => '6379',
'host' => '127.0.0.1',
'port' => '6379',
'pool_namespace' => null,
]
);

$resolver->setAllowedTypes('host', ['string']);
$resolver->setAllowedTypes('port', ['string', 'int']);
$resolver->setAllowedTypes('pool_namespace', ['string', 'null']);
}
}

0 comments on commit 775dabc

Please sign in to comment.