Skip to content

Commit 9fd3171

Browse files
Nyholmcryptiklemur
authored andcommitted
Updated docs to reflect the changes to the bundle
1 parent 556b5ee commit 9fd3171

File tree

3 files changed

+94
-63
lines changed

3 files changed

+94
-63
lines changed

README.md

Lines changed: 90 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,97 @@
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

2122
Run 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

3538
To 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
4572
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+
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
65102
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
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
78114
cache:
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

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "cache/cache-bundle",
33
"type": "library",
4-
"description": "Symfony 2 bundle providing PSR-6 compliant cache services for the user. Many other features.",
4+
"description": "Symfony 2 bundle providing integration between PSR-6 compliant cache services and the framework. It supports cache for sessions, routing and Doctrine",
55
"keywords": [
66
"cache",
77
"psr6",

src/DependencyInjection/Compiler/DoctrineSupportCompilerPass.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@ protected function enableDoctrineSupport(array $config)
6666
continue;
6767
}
6868

69+
// Doctrine can't talk to a PSR-6 cache, so we need a bridge
6970
$bridgeServiceId = sprintf('cache.provider.doctrine.%s.bridge', $cacheType);
7071
$bridgeDef = $this->container->register($bridgeServiceId, DoctrineCacheBridge::class);
7172
$bridgeDef->addArgument(0, new Reference($cacheData['service_id']))
7273
->setPublic(false);
7374

7475
foreach ($cacheData[$type] as $manager) {
75-
$doctrineDefinitionName =
76+
$doctrineDefinitionId =
7677
sprintf(
7778
"doctrine.%s.%s_%s_cache",
7879
($type == 'entity_managers' ? 'orm' : 'odm'),
@@ -81,7 +82,7 @@ protected function enableDoctrineSupport(array $config)
8182
);
8283

8384
// Replace the doctrine entity manager cache with our bridge
84-
$this->container->setAlias($doctrineDefinitionName, $bridgeServiceId);
85+
$this->container->setAlias($doctrineDefinitionId, $bridgeServiceId);
8586
}
8687
}
8788
}

0 commit comments

Comments
 (0)