File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
src/Dflydev/Pimple/Provider/DoctrineOrm Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 1818use Doctrine \Common \Cache \MemcacheCache ;
1919use Doctrine \Common \Cache \MemcachedCache ;
2020use Doctrine \Common \Cache \XcacheCache ;
21+ use Doctrine \Common \Cache \RedisCache ;
2122use Doctrine \Common \Persistence \Mapping \Driver \MappingDriver ;
2223use Doctrine \Common \Persistence \Mapping \Driver \MappingDriverChain ;
2324use 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 }
You can’t perform that action at this time.
0 commit comments