Skip to content

Commit

Permalink
Added Redis Cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Tien Dat Bui committed Oct 25, 2013
1 parent ead43bb commit 0ef3126
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Dflydev/Pimple/Provider/DoctrineOrm/DoctrineOrmServiceProvider.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Doctrine\Common\Cache\MemcacheCache;
use Doctrine\Common\Cache\MemcachedCache;
use Doctrine\Common\Cache\XcacheCache;
use Doctrine\Common\Cache\RedisCache;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain;
use Doctrine\ORM\Configuration;
Expand Down Expand Up @@ -243,6 +244,24 @@ public function register(\Pimple $app)
return $cache;
});

$app['orm.cache.factory.backing_redis'] = $app->protect(function() {
return new \Redis;
});

$app['orm.cache.factory.redis'] = $app->protect(function($cacheOptions) use ($app) {
if (empty($cacheOptions['host']) || empty($cacheOptions['port'])) {
throw new \RuntimeException('Host and port options need to be specified for redis cache');
}

$redis = $app['orm.cache.factory.backing_redis']();
$redis->connect($cacheOptions['host'], $cacheOptions['port']);

$cache = new RedisCache;
$cache->setRedis($redis);

return $cache;
});

$app['orm.cache.factory.array'] = $app->protect(function() {
return new ArrayCache;
});
Expand Down Expand Up @@ -276,6 +295,8 @@ public function register(\Pimple $app)
return $app['orm.cache.factory.memcached']($cacheOptions);
case 'filesystem':
return $app['orm.cache.factory.filesystem']($cacheOptions);
case 'redis':
return $app['orm.cache.factory.redis']($cacheOptions);
default:
throw new \RuntimeException("Unsupported cache type '$driver' specified");
}
Expand Down

0 comments on commit 0ef3126

Please sign in to comment.