1- PHP-Cache cache-bundle [ ![ Build Status ] ( https://travis-ci.org/php-cache/cache-bundle.png?branch=master )] ( https://travis-ci.org/php-cache/cache-bundle )
2- ====================
1+ # PHP-Cache cache-bundle
2+ [ ![ Build Status ] ( https://travis-ci.org/php-cache/cache-bundle.png?branch=master )] ( https://travis-ci.org/php-cache/cache-bundle )
33
4- #### Cache Bundle for Symfony 2
4+ #### Cache Bundle for Symfony 2.6 and above
55
6- Symfony 2 library providing PSR-6 compliant cache services for the user.
7- It also lets you cache your sessions and routes.
6+ This is a Symfony bundle that lets you you integrate your PSR-6 compliant cache service with the framework.
7+ It lets you cache your sessions, routes and Doctrine results and metadata. It also provides an integration with the
8+ debug toolbar.
89
9- The respective cache extensions will be required for your project.
10-
11- Redis uses the php redis extension.
1210
1311#### Requirements
1412
15- - PHP >= 5.6 , < 7.1
16- - Symfony >= 2.7, < 4 .0
13+ - PHP >= 5.5 , < 7.1
14+ - Symfony >= 2.6, ^3 .0
1715- [ Composer] ( http://getcomposer.org )
1816
19- #### To Install
17+ ### To Install
18+
19+ You need to install and enable this bundle and also a PSR-6 cache implementation. In the example below we use the
20+ [ DoctrineAdapterBundle] .
2021
2122Run the following in your project root, assuming you have composer set up for your project
2223``` sh
23- composer.phar require cache/cache-bundle
24+ composer require cache/cache-bundle cache/doctrine-adapter -bundle
2425```
2526
26- Add the bundle to app/AppKernel.php
27+ Add the bundles to app/AppKernel.php
2728
2829``` php
2930$bundles(
30- ...
31- new Cache\CacheBundle\CacheBundle(),
32- ...
31+ // ...
32+ new Cache\CacheBundle\CacheBundle(),
33+ new Cache\Adapter\DoctrineAdapterBundle\DoctrineAdapterBundle(),
34+ // ...
3335);
36+ ```
3437
3538To see all the config options, run ` php app/console config:dump-reference cache ` to view the config settings
3639
3740
41+ #### A word on the cache implementation
42+
43+ This bundle does not register any cache services for you. This is done by [ DoctrineAdapterBundle] you should look
44+ at its documentation to see how you configure that bundle. Below in an example configuration:
45+
46+ ``` yml
47+ cache_adapter_doctrine :
48+ providers :
49+ acme_redis_cache :
50+ type : redis
51+ database : ' foo'
52+ acme_apc_cache :
53+ type : apc
54+ namespace : my_ns
55+ ` ` `
56+
57+ ### Configuration
58+
3859#### Doctrine
3960
40- This bundle allows you to use its services for Doctrine's caching methods of metadata, result, and query.
61+ This bundle allows you to use its services for Doctrine's caching methods of metadata, result, and query. To use this
62+ feature you need to install the [DoctrineBridge].
63+
64+ ` ` ` sh
65+ composer require cache/psr-6-doctrine-bridge
66+ ```
67+
4168
42- If you want doctrine to use this as the result and query cache, add this
69+ If you want Doctrine to use this as the result and query cache, you need this configuration:
4370
4471``` yml
4572cache :
46- doctrine:
47- enabled: true
48- metadata:
49- instance: default
50- entity_managers: [ default ] # the name of your entity_manager connection
51- document_managers: [ default ] # the name of your document_manager connection
52- result:
53- instance: default
54- entity_managers: [ default, read ] # you may specify multiple entity_managers
55- query:
56- instance: default
57- entity_managers: [ default ]
73+ doctrine :
74+ enabled : true
75+ metadata :
76+ service_id : cache.provider.acme_redis_cache
77+ entity_managers : [ default ] # the name of your entity_manager connection
78+ document_managers : [ default ] # the name of your document_manager connection
79+ result :
80+ service_id : cache.provider.acme_redis_cache
81+ entity_managers : [ default, read ] # you may specify multiple entity_managers
82+ query :
83+ service_id : cache.provider.acme_redis_cache
84+ entity_managers : [ default ]
85+ ` ` `
86+
87+ To use this with Doctrine's entity manager, just make sure you have ` useResultCache` and/or `useQueryCache` set to true.
88+
89+ ` ` ` php
90+ $em = $this->get('doctrine.orm.entity_manager');
91+ $q = $em->('SELECT u.* FROM Acme\User u');
92+ $q->useResultCache(true, 3600);
93+ $result = $q->getResult();
94+
5895` ` `
5996
6097# ### Session
@@ -63,11 +100,10 @@ This bundle even allows you to store your session data in one of your cache clus
63100
64101` ` ` yml
65102cache:
66- session :
67- enabled : true
68- instance : default
69- prefix : " session_"
70- ttl : 7200
103+ session:
104+ enabled: true
105+ service_id: cache.provider.acme_redis_cache
106+ ttl: 7200
71107` ` `
72108
73109# ### Router
@@ -76,39 +112,33 @@ This bundle also provides router caching, to help speed that section up. To enab
76112
77113` ` ` yml
78114cache:
79- router :
80- enabled : true
81- instance : default
115+ router:
116+ enabled: true
117+ service_id: cache.provider.acme_redis_cache
82118` ` `
83119
84- If you change any of your routes, you will need to clear all of the route_* keys in your cache.
85-
120+ If you change any of your routes, you will need to clear the cache. If you use a cache implementation that supports
121+ tagging (implements [TaggablePoolTrait](https://github.com/php-cache/taggable-cache/blob/master/src/TaggablePoolInterface.php))
122+ you can clear the cache tagged with `routing`.
86123
87- #### To Use
88124
89- To use this with doctrine's entity manager, just make sure you have ` useResultCache` and/or `useQueryCache` set to true. If you want to use the user cache, just grab the service out of the container like so:
125+ # ## Clearing the cache
90126
91- ` ` ` php
92- // Change default to the name of your instance
93- $cache = $container->get( 'cache.instance.default' );
94- // Or
95- $cache = $container->get( 'cache.default' );
96- ` ` `
127+ If you want to clear the cache you can run the following commands.
97128
98- Here is an example usage of the service :
129+ ` ` ` sh
130+ php app/console cache:flush session
131+ php app/console cache:flush routing
132+ php app/console cache:flush doctrine
99133
100- ` ` ` php
101- $cache = $this->get( 'cache.instance.default' );
102- $item = $cache->getItem('test');
103- if ($item->isHit()) {
104- var_dump($item->get());
105-
106- return;
107- }
108-
109- $cache->saveItem('test', $em->find('AcmeDemoBundle:User', 1), 3600);
134+ echo "Or you could run: "
135+ php app/console cache:flush all
110136` ` `
111137
112138# ## Need Help?
113139
114- Create an issue if you've found a bug, or ping one of us on twitter : @aequasi or @TobiasNyholm
140+ Create an issue if you've found a bug, or ping one of us on twitter : @aequasi or @TobiasNyholm
141+
142+
143+ [DoctrineAdapterBundle]:https://github.com/php-cache/doctrine-adapter-bundle
144+ [DoctrineBridge]:https://github.com/php-cache/doctrine-bridge
0 commit comments