├── Command ├── CacheDeleteAllCommand.php └── CacheFlushCommand.php ├── DependencyInjection ├── Compiler │ └── ServiceCreationCompilerPass.php ├── Configuration.php └── LiipDoctrineCacheExtension.php ├── LiipDoctrineCacheBundle.php ├── README.md ├── Resources ├── config │ └── services.xml └── meta │ └── LICENSE └── composer.json /Command/CacheDeleteAllCommand.php: -------------------------------------------------------------------------------- 1 | setName('liip:doctrine-cache:delete-all'); 26 | $this->setDescription('Clean the given cache'); 27 | $this->addArgument( 28 | 'cache-name', InputArgument::REQUIRED, 'Which cache to clean?' 29 | ); 30 | $this->addArgument( 31 | 'use-namespace', 32 | InputArgument::OPTIONAL, 33 | 'Which namespace to use (defaults to the one specified in the container configuration)' 34 | ); 35 | } 36 | 37 | /** 38 | * {@inheritdoc} 39 | */ 40 | protected function execute(InputInterface $input, OutputInterface $output) 41 | { 42 | // Retrieve the cache provider associated to the given cache-name 43 | $cacheName = $input->getArgument('cache-name'); 44 | $serviceName = 'liip_doctrine_cache.ns.'.$cacheName; 45 | $cacheProvider = $this->getContainer()->get($serviceName); 46 | 47 | if ($cacheProvider instanceof CacheProvider) { 48 | // In case we force another namespace, force it in the cache provider 49 | $namespace = $input->getArgument('use-namespace'); 50 | if ('' != $namespace) { 51 | $cacheProvider->setNamespace($namespace); 52 | } else { 53 | $namespace = $cacheProvider->getNamespace(); 54 | } 55 | 56 | // Do the actual cache invalidation for the given namespace 57 | $cacheProvider->deleteAll(); 58 | } else { 59 | // Should not happen... 60 | throw new \RuntimeException(sprintf( 61 | 'Unable to get a cache named %s from the container', 62 | $cacheName 63 | )); 64 | } 65 | 66 | $output->writeln(sprintf( 67 | 'The namespace %s of cache %s has been fully invalidated', 68 | $namespace, 69 | $cacheName 70 | )); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Command/CacheFlushCommand.php: -------------------------------------------------------------------------------- 1 | setName('liip:doctrine-cache:flush'); 21 | $this->setAliases(array('liip:doctrine-cache:clear')); 22 | $this->setDescription('Clean the given cache'); 23 | $this->addArgument( 24 | 'cache-name', InputArgument::REQUIRED, 'Which cache to clean?' 25 | ); 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function execute(InputInterface $input, OutputInterface $output) 32 | { 33 | $serviceName = 'liip_doctrine_cache.ns.'.$input->getArgument('cache-name'); 34 | 35 | $this->getContainer()->get($serviceName)->flushAll(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /DependencyInjection/Compiler/ServiceCreationCompilerPass.php: -------------------------------------------------------------------------------- 1 | getParameter('liip_doctrine_cache.namespaces'); 16 | 17 | foreach ($namespaces as $name => $config) { 18 | $id = 'liip_doctrine_cache.'.$config['type']; 19 | if (!$container->hasDefinition($id)) { 20 | throw new \InvalidArgumentException('Supplied cache type is not supported: '.$config['type']); 21 | } 22 | 23 | $namespace = empty($config['namespace']) ? $name : $config['namespace']; 24 | $service = $container 25 | ->setDefinition('liip_doctrine_cache.ns.'.$name, new DefinitionDecorator($id)) 26 | ->addMethodCall('setNamespace', array($namespace)); 27 | 28 | foreach ($config['alias'] as $alias) { 29 | $container->setAlias('liip_doctrine_cache.ns.'.$alias, 'liip_doctrine_cache.ns.'.$name); 30 | } 31 | 32 | switch ($config['type']) { 33 | case 'memcache': 34 | if (empty($config['id'])) { 35 | $memcacheHost = !empty($config['host']) ? $config['host'] : '%liip_doctrine_cache.memcache_host%'; 36 | $memcachePort = isset($config['port']) ? $config['port'] : '%liip_doctrine_cache.memcache_port%'; 37 | $memcacheTimeout = !empty($config['timeout']) ? $config['timeout'] : '%liip_doctrine_cache.memcache_timeout%'; 38 | $memcache = new Definition('Memcache'); 39 | $memcache->addMethodCall('addServer', array( 40 | $memcacheHost, $memcachePort, $memcacheTimeout 41 | )); 42 | $memcache->setPublic(false); 43 | $memcacheId = sprintf('liip_doctrine_cache.%s_memcache_instance', $name); 44 | $container->setDefinition($memcacheId, $memcache); 45 | } else { 46 | $memcacheId = $config['id']; 47 | } 48 | 49 | $service->addMethodCall('setMemcache', array(new Reference($memcacheId))); 50 | break; 51 | case 'memcached': 52 | if (empty($config['id'])) { 53 | $memcachedHost = !empty($config['host']) ? $config['host'] : '%liip_doctrine_cache.memcached_host%'; 54 | $memcachedPort = !empty($config['port']) ? $config['port'] : '%liip_doctrine_cache.memcached_port%'; 55 | $memcached = new Definition('Memcached'); 56 | $memcached->addMethodCall('addServer', array( 57 | $memcachedHost, $memcachedPort 58 | )); 59 | $memcached->setPublic(false); 60 | $memcachedId = sprintf('liip_doctrine_cache.%s_memcached_instance', $name); 61 | $container->setDefinition($memcachedId, $memcached); 62 | } else { 63 | $memcachedId = $config['id']; 64 | } 65 | 66 | $service->addMethodCall('setMemcached', array(new Reference($memcachedId))); 67 | break; 68 | case 'redis': 69 | if (empty($config['id'])) { 70 | $redisHost = !empty($config['host']) ? $config['host'] : '%liip_doctrine_cache.redis_host%'; 71 | $redisPort = !empty($config['port']) ? $config['port'] : '%liip_doctrine_cache.redis_port%'; 72 | $redisTimeout = !empty($config['timeout']) ? $config['timeout'] : '%liip_doctrine_cache.redis_timeout%'; 73 | $redis = new Definition('Redis'); 74 | $redis->addMethodCall('connect', array( 75 | $redisHost, $redisPort, $redisTimeout 76 | )); 77 | $redis->setPublic(false); 78 | $redisId = sprintf('liip_doctrine_cache.%s_redis_instance', $name); 79 | $container->setDefinition($redisId, $redis); 80 | } else { 81 | $redisId = $config['id']; 82 | } 83 | 84 | $service->addMethodCall('setRedis', array(new Reference($redisId))); 85 | break; 86 | case 'file_system': 87 | case 'php_file': 88 | $directory = !empty($config['directory']) ? $config['directory'] : '%kernel.cache_dir%/doctrine/cache'; 89 | $extension = !empty($config['extension']) ? $config['extension'] : null; 90 | 91 | $service->setArguments(array($directory, $extension)); 92 | break; 93 | } 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /DependencyInjection/Configuration.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | class Configuration implements ConfigurationInterface 18 | { 19 | /** 20 | * Generates the configuration tree. 21 | * 22 | * @return TreeBuilder 23 | */ 24 | public function getConfigTreeBuilder() 25 | { 26 | $treeBuilder = new TreeBuilder(); 27 | $rootNode = $treeBuilder->root('liip_doctrine_cache', 'array'); 28 | 29 | $rootNode 30 | ->fixXmlConfig('namespace', 'namespaces') 31 | ->children() 32 | ->arrayNode('namespaces') 33 | ->useAttributeAsKey('name') 34 | ->prototype('array') 35 | ->children() 36 | ->scalarNode('namespace')->defaultNull()->end() 37 | ->scalarNode('type')->isRequired()->cannotBeEmpty()->end() 38 | ->scalarNode('host')->defaultNull()->end() 39 | ->scalarNode('port')->defaultNull()->end() 40 | ->scalarNode('timeout')->defaultNull()->end() 41 | ->scalarNode('id')->defaultNull()->end() 42 | ->scalarNode('directory')->defaultNull()->end() 43 | ->scalarNode('extension')->defaultNull()->end() 44 | ->arrayNode('alias') 45 | ->beforeNormalization() 46 | ->ifTrue(function ($v) { return !is_array($v); }) 47 | ->then(function ($v) { return (array) $v; }) 48 | ->end() 49 | ->prototype('scalar')->end() 50 | ->defaultValue(array()) 51 | ->end() 52 | ->end() 53 | ->end() 54 | ->end() 55 | ->end(); 56 | 57 | return $treeBuilder; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /DependencyInjection/LiipDoctrineCacheExtension.php: -------------------------------------------------------------------------------- 1 | processConfiguration($configuration, $configs); 21 | 22 | $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); 23 | $loader->load('services.xml'); 24 | 25 | $container->setParameter($this->getAlias().'.namespaces', $config['namespaces']); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /LiipDoctrineCacheBundle.php: -------------------------------------------------------------------------------- 1 | addCompilerPass(new ServiceCreationCompilerPass()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DoctrineCacheBundle 2 | =================== 3 | 4 | This Bundle provides integration into Symfony2 with the Doctrine Common Cache layer. 5 | 6 | This Project Has Been Deprecated 7 | ================================ 8 | [![This Project Has Been Deprecated in favor of doctrine/doctrine-cache-bundle.](http://www.repostatus.org/badges/0.1.0/abandoned.svg)](http://www.repostatus.org/#abandoned) 9 | 10 | in favor of https://github.com/doctrine/DoctrineCacheBundle. 11 | 12 | 13 | Installation 14 | ============ 15 | 16 | ### 1. Add the bundle to your composer.json 17 | 18 | ``` 19 | "require": { 20 | ... 21 | "liip/doctrine-cache-bundle": "~1.0" 22 | } 23 | ``` 24 | 25 | ### 2. Install the bundle using composer 26 | 27 | ```bash 28 | $ php composer.phar update liip/doctrine-cache-bundle 29 | ``` 30 | 31 | ### 3. Add this bundle to your application's kernel: 32 | 33 | ```php 34 | get('liip_doctrine_cache.ns.[your_name]')` in your code. 90 | 91 | Custom cache types 92 | ================== 93 | 94 | Simply define a new type by defining a service named `liip_doctrine_cache.[type name]`. 95 | Note the service needs to implement ``Doctrine\Common\Cache\Cache`` interface. 96 | 97 | Development mode 98 | ================ 99 | 100 | In development mode you do not want to cache things over more than one request. An easy 101 | solution for this is to use the array cache in the dev environment. 102 | 103 | #config.yml 104 | liip_doctrine_cache: 105 | namespaces: 106 | presta_sitemap: 107 | type: file_system 108 | 109 | # config_dev.yml 110 | liip_doctrine_cache: 111 | namespaces: 112 | presta_sitemap: 113 | type: array 114 | 115 | The array cache will be lost after each request, so effectively only cache if you access 116 | the same data within one single request. 117 | -------------------------------------------------------------------------------- /Resources/config/services.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | Doctrine\Common\Cache\ApcCache 10 | Doctrine\Common\Cache\ArrayCache 11 | Doctrine\Common\Cache\FilesystemCache 12 | Doctrine\Common\Cache\MemcacheCache 13 | localhost 14 | 11211 15 | 1 16 | Doctrine\Common\Cache\MemcachedCache 17 | localhost 18 | 11211 19 | Doctrine\Common\Cache\RedisCache 20 | localhost 21 | 6379 22 | 2 23 | Doctrine\Common\Cache\PhpFileCache 24 | Doctrine\Common\Cache\WinCacheCache 25 | Doctrine\Common\Cache\XcacheCache 26 | Doctrine\Common\Cache\ZendDataCache 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Resources/meta/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Liip 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "liip/doctrine-cache-bundle", 3 | "description": "This Bundle provides integration into Symfony2 with the Doctrine Common Cache layer.", 4 | "keywords": ["symfony2", "cache"], 5 | "type": "symfony-bundle", 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Liip AG", 10 | "homepage": "http://www.liip.ch/" 11 | } 12 | ], 13 | "require": { 14 | "php": ">=5.3.0", 15 | "symfony/symfony": ">=2.0", 16 | "doctrine/common": ">=2.2" 17 | }, 18 | "autoload": { 19 | "psr-0": { 20 | "Liip\\DoctrineCacheBundle\\": "" 21 | } 22 | }, 23 | "target-dir" : "Liip/DoctrineCacheBundle", 24 | "extra": { 25 | "branch-alias": { 26 | "dev-master": "1.0.x-dev" 27 | } 28 | } 29 | } 30 | --------------------------------------------------------------------------------