There is no way to remove entity cache items

Created on 10 October 2024, 2 months ago

Problem/Motivation

Drupal\Core\Cache\MemoryBackend::garbageCollection is a no-op.

When testing a long-running drush process that creates 100s of thousands entities we stumbled upon a memory issue. RAM consumption was growing with every iteration. This was expected, as it's a single process and all the created entities were going to the entity cache. Easy-peasy, let's just clear the entity cache with $storage->resetCache(), right? Wrong :) This had no effect on the memory consumption. It turned out that MemoryBackend::resetCache only updates the expires property and removal should be done in ::garbageCollection, which looks like this:

public function garbageCollection() {
}

Steps to reproduce

  1. Load an entity
  2. Call $storage->resetCache()
  3. Run \Drupal::service('entity.memory_cache')->garbageCollection();
  4. Get the cache item with $allow_invalid set to TRUE

Proposed resolution

Remove invalid cache items when ->garbageCollection() is invoked.

Remaining tasks

None.

User interface changes

None.

Introduced terminology

None.

API changes

None.

Data model changes

None.

Release notes snippet

Drupal\Core\Cache\MemoryBackend::garbageCollection() removes invalid cache items from memory.

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component

cache system

Created by

πŸ‡΅πŸ‡±Poland blazey

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024