Skip to content

Commit 667baa9

Browse files
committed
Merge pull request #20 from tdbui83/master
Added Redis Cache
2 parents ead43bb + 0ef3126 commit 667baa9

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/Dflydev/Pimple/Provider/DoctrineOrm/DoctrineOrmServiceProvider.php

100644100755
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Doctrine\Common\Cache\MemcacheCache;
1919
use Doctrine\Common\Cache\MemcachedCache;
2020
use Doctrine\Common\Cache\XcacheCache;
21+
use Doctrine\Common\Cache\RedisCache;
2122
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
2223
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain;
2324
use Doctrine\ORM\Configuration;
@@ -243,6 +244,24 @@ public function register(\Pimple $app)
243244
return $cache;
244245
});
245246

247+
$app['orm.cache.factory.backing_redis'] = $app->protect(function() {
248+
return new \Redis;
249+
});
250+
251+
$app['orm.cache.factory.redis'] = $app->protect(function($cacheOptions) use ($app) {
252+
if (empty($cacheOptions['host']) || empty($cacheOptions['port'])) {
253+
throw new \RuntimeException('Host and port options need to be specified for redis cache');
254+
}
255+
256+
$redis = $app['orm.cache.factory.backing_redis']();
257+
$redis->connect($cacheOptions['host'], $cacheOptions['port']);
258+
259+
$cache = new RedisCache;
260+
$cache->setRedis($redis);
261+
262+
return $cache;
263+
});
264+
246265
$app['orm.cache.factory.array'] = $app->protect(function() {
247266
return new ArrayCache;
248267
});
@@ -276,6 +295,8 @@ public function register(\Pimple $app)
276295
return $app['orm.cache.factory.memcached']($cacheOptions);
277296
case 'filesystem':
278297
return $app['orm.cache.factory.filesystem']($cacheOptions);
298+
case 'redis':
299+
return $app['orm.cache.factory.redis']($cacheOptions);
279300
default:
280301
throw new \RuntimeException("Unsupported cache type '$driver' specified");
281302
}

0 commit comments

Comments
 (0)