Skip to content
Snippets Groups Projects
Commit 28123e2a authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2344691 by Wim Leers: Update core.api.php's Cache API documentation:...

Issue #2344691 by Wim Leers: Update core.api.php's Cache API documentation: cache tags are now set as strings
parent 338e9669
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -461,14 +461,15 @@ ...@@ -461,14 +461,15 @@
* *
* @section tags Cache Tags * @section tags Cache Tags
* *
* The fourth argument of the set() method can be used to specify cache tags, * The fourth argument of the @code set() @endcode method can be used to specify
* which are used to identify what type of data is included in each cache item. * cache tags, which are used to identify which data is included in each cache
* Each cache item can have multiple cache tags, and each cache tag has a string * item. A cache item can have multiple cache tags (an array of cache tags), and
* key and a value. The value can be: * each cache tag is a string. The convention is to generate cache tags of the
* - TRUE, to indicate that this type of data is present in the cache item. * form @code <prefix>:<suffix> @endcode. Usually, you'll want to associate the
* - An array of values. For example, the "node" tag indicates that particular * cache tags of entities, or entity listings. You won't have to manually
* node's data is present in the cache item, so its value is an array of node * construct cache tags for them — just get their cache tags via
* IDs. * \Drupal\Core\Entity\EntityInterface::getCacheTags() and
* \Drupal\Core\Entity\EntityTypeInterface::getListCacheTags().
* Data that has been tagged can be invalidated as a group: no matter * Data that has been tagged can be invalidated as a group: no matter
* the Cache ID (cid) of the cache item, no matter in which cache bin a cache * the Cache ID (cid) of the cache item, no matter in which cache bin a cache
* item lives; as long as it is tagged with a certain cache tag, it will be * item lives; as long as it is tagged with a certain cache tag, it will be
...@@ -490,9 +491,10 @@ ...@@ -490,9 +491,10 @@
* @code * @code
* // A cache item with nodes, users, and some custom module data. * // A cache item with nodes, users, and some custom module data.
* $tags = array( * $tags = array(
* 'my_custom_tag' => TRUE, * 'my_custom_tag',
* 'node' => array(1, 3), * 'node:1',
* 'user' => array(7), * 'node:3',
* 'user:7',
* ); * );
* \Drupal::cache()->set($cid, $data, CacheBackendInterface::CACHE_PERMANENT, $tags); * \Drupal::cache()->set($cid, $data, CacheBackendInterface::CACHE_PERMANENT, $tags);
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment