Support external entities related custom cache tag

Created on 19 October 2020, about 4 years ago
Updated 26 April 2023, over 1 year ago

Problem/Motivation

When we use external entities in search api,we found external entities cache will not clear when we rebuild tracker information.
We need manually clear that cache,that would be not intelligent.

Steps to reproduce

1.Create one external entities type.
2.Use search api to create a index which data source from external entites.
3.Create a view make it list data from search api index,and set cache tag as " Search API (tag-based)".
4.After we rebuild tracker for search api,we found data not changed

Proposed resolution

We can add a field for external entities named persistent_cache_tags,then update form make it can be added multiply,In external entities storage and entity type class, use getCacheTags and getCacheTagsToInvalidate function to realize it.

I found the cache tags logic like this:

<?php
  protected function setPersistentCache($entities) {
    if (!$this->entityType->isPersistentlyCacheable()) {
      return;
    }

    $cache_tags = [
      $this->entityTypeId . '_values',
      'entity_field_info',
    ];

    foreach ($entities as $id => $entity) {
      $max_age = $this->getExternalEntityType()->getPersistentCacheMaxAge();
      $expire = $max_age === Cache::PERMANENT
        ? Cache::PERMANENT
        : $this->time->getRequestTime() + $max_age;
      $this->cacheBackend->set($this->buildCacheId($id), $entity, $expire, $cache_tags);
    }
  }

?>

So this logic get cache tags need update,otherwise our custom cache tag can't merged into it.

Feature request
Status

Needs review

Component

Code

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024