2
2
=====
3
3
4
4
Using cache is a great way of making you application run quicker. The Symfony cache
5
- component is shipped with many adapters to cache storages that all are developed
6
- for high performance.
5
+ component is shipped with many adapters to different storages. Every adapter is
6
+ developed for high performance.
7
7
8
8
Basic uses of the cache looks like this.
9
9
@@ -16,11 +16,13 @@ Basic uses of the cache looks like this.
16
16
$item->expiresAfter(3600);
17
17
18
18
// Do some HTTP request or heavy computations
19
- $computedValue = ... ;
19
+ $computedValue = 'foobar' ;
20
20
21
21
return $computedValue;
22
22
});
23
23
24
+ echo $value; // 'foobar'
25
+
24
26
$pool->delete('some_key');
25
27
26
28
@@ -31,10 +33,11 @@ these at the :ref:`component documentation <component-cache>`.
31
33
Configuring Cache with SymfonyFrameworkBundle
32
34
---------------------------------------------
33
35
34
- When configuring the the cache component there are a few concepts you should know:
36
+ When configuring the the cache component there are a few concepts you should know
37
+ of:
35
38
36
39
**Pool **
37
- This is a service that you will interact with. Each pool will always has
40
+ This is a service that you will interact with. Each pool will always have
38
41
its own namespace and cache items. There is never a conflict between pools.
39
42
**Adapter **
40
43
An adapter is a *template * that you use to create Pools.
@@ -43,8 +46,8 @@ When configuring the the cache component there are a few concepts you should kno
43
46
44
47
There are two pools that are always enabled by default. They are ``cache.app `` and
45
48
``cache.system ``. The system cache is use for things like annotations, serializer,
46
- and validation. The ```cache.app `` is used in your code. You can configure witch
47
- adapters (templates ) they use by using the ``app `` and ``system `` key like:
49
+ and validation. The ```cache.app `` is used in your code. You can configure which
50
+ adapter (template ) they use by using the ``app `` and ``system `` key like:
48
51
49
52
.. code-block :: yaml
50
53
@@ -56,17 +59,19 @@ adapters (templates) they use by using the ``app`` and ``system`` key like:
56
59
The Cache component comes with a series of adapters already created:
57
60
58
61
- :ref: `cache.adapter.apcu <component-cache-apcu-adapter >`
59
- - :ref: `cache.adapter.chain <component-cache-chain-adapter >`
62
+ - :ref: `ChainAdapter <component-cache-chain-adapter >`
60
63
- :ref: `cache.adapter.doctrine <component-cache-doctrine-adapter >`
61
64
- :ref: `cache.adapter.filesystem <component-cache-filesystem-adapter >`
62
65
- :ref: `cache.adapter.memcached <component-cache-memcached-adapter >`
63
66
- :ref: `cache.adapter.pdo <component-cache-pdo-doctrine-dbal-adapter >`
64
- - :ref: `cache.adapter.array <component-cache-php-array-adapter >`
65
- - :ref: `cache.adapter.file <component-cache-php-files-adapter >`
66
- - :ref: `cache.adapter.proxy <component-cache-proxy-adapter >`
67
+ - :ref: `PHPArrayAdapter <component-cache-php-array-adapter >`
68
+ - :ref: `PHPFileAdapter <component-cache-php-files-adapter >`
69
+ - :ref: `ProxyAdapter <component-cache-proxy-adapter >`
67
70
- :ref: `cache.adapter.redis <component-cache-redis-adapter >`
68
71
- cache.adapter.psr6
69
72
- cache.adapter.system
73
+ - NullAdapter
74
+ - cache.adapter.array
70
75
71
76
Some of these adapters could be configured via shortcuts:
72
77
@@ -83,7 +88,7 @@ Some of these adapters could be configured via shortcuts:
83
88
default_pdo_provider : ' doctrine.dbal.default_connection'
84
89
85
90
Using the *providers * above, they will configure the adapters and create pools (services)
86
- with names :
91
+ with service ids :
87
92
88
93
- ``cache.doctrine ``
89
94
- ``cache.psr6 ``
@@ -111,9 +116,9 @@ You can also create more customized pools. All you need is an adapter
111
116
provider : ' memcached://user:password@example.com'
112
117
113
118
The configuration above will create 3 services: ``my_cache_pool ``, ``cache.acme ``
114
- and ``cache.foobar ``. The ``my_cache_pool `` pool is using the :ref: ` ArrayAdapter < component-cache-php-array-adapter >`
119
+ and ``cache.foobar ``. The ``my_cache_pool `` pool is using the ArrayAdapter
115
120
and the other two are using the :ref: `MemcachedAdapter <component-cache-memcached-adapter >`.
116
- Pool ``cache.acme `` is using the Memcached server on localhost and ``cache.foobar ``
121
+ The ``cache.acme `` pool is using the Memcached server on localhost and ``cache.foobar ``
117
122
is using the Memcached server at example.com.
118
123
119
124
For advanced configurations it could sometimes be useful to use a pool as an adapter.
@@ -169,12 +174,19 @@ case we have to recalculate the value.
169
174
Clearing the Cache
170
175
------------------
171
176
172
- When the ``bin/console cache:clear `` command is executed it will use
177
+ To clear the cache you can use the ``bin/console cache:pool:clear [pool] `` command.
178
+ That will remove all the entries from your storage and you wil have to recalcuate
179
+ all values. You can also group your pools into "cache clearers". There 3 cache clearer
180
+ by default:
181
+
182
+ * cache.global_clearer
183
+ * cache.system_clearer
184
+ * cache.app_clearer
173
185
174
- Only the system cached is cleared..
186
+ The global clearer clears all the cache in every pool. The system cache clearer
187
+ is used in the ``bin/console cache:clear `` command. The app clearer is the default
188
+ clearer.
175
189
176
- cache.system_clearer
177
- cache.default_clearer
178
- cache.app_clearer
190
+ .. code-block :: terminal
179
191
180
- cache.global_clearer
192
+ $ bin/console cache:pool:clear cache.app_clearer
0 commit comments