@@ -10,20 +10,22 @@ change in the state of your model. The most basic kind of invalidation is direct
10
10
items deletion. But when the state of a primary resource has spread accross
11
11
several cached items, keeping them in sync can be difficult.
12
12
13
- The Symfony Cache component provides two mechanisms to help solve this problem:
13
+ The Symfony Cache component provides two mechanisms to help solving this problem:
14
14
15
- * Tags based invalidation for managing data dependencies;
16
- * Expiration based invalidation for time related dependencies.
15
+ * :ref: ` Tags based invalidation < cache-component-tags >` for managing data dependencies;
16
+ * :ref: ` Expiration based invalidation < cache-component-expiration >` for time related dependencies.
17
17
18
- .. versionadded :: 3.2
19
- Tags based invalidation was introduced in Symfony 3.2.
18
+ .. _cache-component-tags :
20
19
21
20
Using Cache Tags
22
21
----------------
23
22
23
+ .. versionadded :: 3.2
24
+ Tags based invalidation was introduced in Symfony 3.2.
25
+
24
26
To benefit from tags based invalidation, you need to attach the proper tags to
25
- each cached items . Each tag is a plain string identifier that you can use at any
26
- time to trigger the removal of all items that had this tag attached to them .
27
+ each cached item . Each tag is a plain string identifier that you can use at any
28
+ time to trigger the removal of all items associated with this tag.
27
29
28
30
To attach tags to cached items, you need to use the
29
31
:method: `Symfony\\ Component\\ Cache\\ CacheItem::tag ` method that is implemented by
@@ -36,14 +38,14 @@ cache items, as returned by cache adapters::
36
38
$item->tag(array('tag_2', 'tag_3'));
37
39
$cache->save($item);
38
40
39
- If ``$cache `` implements :class: `Symfony\\ Component\\ Cache\\ TagAwareAdapterInterface `,
41
+ If ``$cache `` implements :class: `Symfony\\ Component\\ Cache\\ Adapter \\ TagAwareAdapterInterface `,
40
42
you can invalidate the cached items by calling
41
- :method: `Symfony\\ Component\\ Cache\\ TagAwareAdapterInterface::invalidateTags `::
43
+ :method: `Symfony\\ Component\\ Cache\\ Adapter \\ TagAwareAdapterInterface::invalidateTags `::
42
44
43
45
// invalidate all items related to `tag_1` or `tag_3`
44
46
$cache->invalidateTags(array('tag_1', 'tag_3'));
45
47
46
- // if you know the cache key, you can of course delete directly
48
+ // if you know the cache key, you can also delete the item directly
47
49
$cache->deleteItem('cache_key');
48
50
49
51
Using tags invalidation is very useful when tracking cache keys becomes difficult.
@@ -78,6 +80,8 @@ your fronts and have very fast invalidation checks::
78
80
new RedisAdapter('redis://localhost')
79
81
);
80
82
83
+ .. _cache-component-expiration :
84
+
81
85
Using Cache Expiration
82
86
----------------------
83
87
0 commit comments