Skip to content
This repository was archived by the owner on Feb 17, 2022. It is now read-only.

7.x 2.x cache warming

Andy Truong edited this page Jan 9, 2014 · 9 revisions

Config

To flush cached tags on some special events of Drupal, define:

# File: %your_module/config/cache_warming.yml
tags:
  entity_update: ['my_tag_1', 'my_tag_2']
  enttiy_delete: ['%entity_type:%entity_bundle:%entity_id', '%type:%bundle:%id']
  user_login: ['view:my_view:block_1']
  user_logout: []

Notes:

  • 'view:my_view:block_1', will warm view my_view, display ID block_1.

Supported tokens:

  • %entity_type, %type
  • %entity_bundle, %bundle
  • %entity_id, %id
  • %process:relationships: Start cache warming process on related entities with
  • %uid: UID of current user
  • %roles: Replace on tag to multiple tags, with context user's roles

When taxonomy.module is available

  • %taxonomy_terms: Replace one tag to multiple tags, with taxonomy-term attached to entity.
  • %process:taxonomy_terms: Start cache warming process on related taxonomy term.

When entity_reference.module is available

  • %entity_references: …
  • %process:entity_references: …

When relation.module is available

  • %relationships: replace on tag to multiple tags, with ID if related entity.
  • %process:relationships: Start cache warming process on entities has relationship on current entity.

To define your own event:

use \Drupal\at_base\Cache\Warmer as CacheWarmer;

/**
 * Implements hook_user_login()
 */
function at_base_user_logout($account) {
  at_container('cache.warmer')
    ->setEventName('user_logout')
    ->setContext(array('entity_type' => 'user', 'entity' => $account))
    ->warm()
  ;
}

Clone this wiki locally