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 )
3
3
4
- #### Cache Bundle for Symfony 2
4
+ #### Cache Bundle for Symfony 2.6 and above
5
5
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.
8
9
9
- The respective cache extensions will be required for your project.
10
-
11
- Redis uses the php redis extension.
12
10
13
11
#### Requirements
14
12
15
- - PHP >= 5.6 , < 7.1
16
- - Symfony >= 2.7, < 4 .0
13
+ - PHP >= 5.5 , < 7.1
14
+ - Symfony >= 2.6, ^3 .0
17
15
- [ Composer] ( http://getcomposer.org )
18
16
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] .
20
21
21
22
Run the following in your project root, assuming you have composer set up for your project
22
23
``` sh
23
- composer.phar require cache/cache-bundle
24
+ composer require cache/cache-bundle cache/doctrine-adapter -bundle
24
25
```
25
26
26
- Add the bundle to app/AppKernel.php
27
+ Add the bundles to app/AppKernel.php
27
28
28
29
``` php
29
30
$bundles(
30
- ...
31
- new Cache\CacheBundle\CacheBundle(),
32
- ...
31
+ // ...
32
+ new Cache\CacheBundle\CacheBundle(),
33
+ new Cache\Adapter\DoctrineAdapterBundle\DoctrineAdapterBundle(),
34
+ // ...
33
35
);
36
+ ```
34
37
35
38
To see all the config options, run ` php app/console config:dump-reference cache ` to view the config settings
36
39
37
40
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
+
38
59
#### Doctrine
39
60
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
+
41
68
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:
43
70
44
71
``` yml
45
72
cache :
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
+
58
95
` ` `
59
96
60
97
# ### Session
@@ -63,11 +100,10 @@ This bundle even allows you to store your session data in one of your cache clus
63
100
64
101
` ` ` yml
65
102
cache:
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
71
107
` ` `
72
108
73
109
# ### Router
@@ -76,39 +112,33 @@ This bundle also provides router caching, to help speed that section up. To enab
76
112
77
113
` ` ` yml
78
114
cache:
79
- router :
80
- enabled : true
81
- instance : default
115
+ router:
116
+ enabled: true
117
+ service_id: cache.provider.acme_redis_cache
82
118
` ` `
83
119
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`.
86
123
87
- #### To Use
88
124
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
90
126
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.
97
128
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
99
133
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
110
136
` ` `
111
137
112
138
# ## Need Help?
113
139
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