militag.blogg.se

Drupal cache contexts
Drupal cache contexts








drupal cache contexts

Instead, it should retrieve cache tags to invalidate for a single entity using its ::getCacheTags() method, e.g., $node->getCacheTags(), $user->getCacheTags(), $view->getCacheTags() etc.

#Drupal cache contexts code#

(All specific entity types and configuration objects inherit from those.)Īlthough many entity types follow a predictable cache tag format of :, third-party code shouldn't rely on this. configuration - these have cache tags of the form config:ĭrupal provides cache tags for entities & configuration automatically - see the Entity base class and the ConfigBase base class.Config entity types use the cache tag of the underlying configuration object. entities - these have cache tags of the form : as well as _list and _list: to invalidate lists of entities.The data that Drupal manages fall in 3 categories: library_info - cache tag for asset libraries.config:system.performance - cache tag for the system.performance configuration.Applicable to any entity type in following format: _list. node_list - list cache tag for Node entities (invalidated whenever any Node entity is updated, deleted or created, i.e., when a listing of nodes may need to change).user:3 - cache tag for User entity 3 (invalidated whenever it changes).node:5 - cache tag for Node entity 5 (invalidated whenever it changes).The only rule is that it cannot contain spaces. Syntaxīy convention, they are of the form thing:identifier - and when there's no concept of multiple instances of a thing, it is of the form thing. They're sets because a single cache item can depend on (be invalidated by) many cache tags. None of those 3 methods allow us to invalidate the cache items that contain an entity that was modified, because that was impossible to know! What?Ĭache tags are passed around in sets (order doesn't matter) of strings, so they are typehinted to string. Note: Drupal 7 offered 3 ways of invalidating cache items: invalidate a specific CID, invalidate using a CID prefix, or invalidate everything in a cache bin. Which then brings us to the famous quote "There are only two hard things in Computer Science: cache invalidation and naming things." - that is, how are you going to invalidate all cache items where the content is being used? Which means the same content could be cached in dozens of places. In any of the places where the content is used, it may be cached. In other words: it is impossible to know ahead of time where some content is going to be used. This is essential for a content management system/framework like Drupal because the same content can be reused in many ways. Cache tags describe dependencies on data managed by Drupal Why?Ĭache tags provide a declarative way to track which cache items depend on some data managed by Drupal.










Drupal cache contexts