Skip to content

Commit

Permalink
Merge pull request #20 from tdbui83/master
Browse files Browse the repository at this point in the history
Added Redis Cache
  • Loading branch information
simensen committed Oct 25, 2013
2 parents ead43bb + 0ef3126 commit 667baa9
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 667baa9

Please sign in to comment.