StaticCache is confusingly named and shouldn't extend DatabaseBackend

Created on 24 January 2024, about 1 year ago

Problem/Motivation

This is really confusing:

class StaticCache extends DatabaseBackend implements StaticCacheInterface {

Core's DatabaseBackend is a cache backend implementation. Classes that extend it or implement CacheBackendInterface should be other types of backend -- memory backend, file backend, etc.

But that's not what the StaticCache class is doing at all. It's using DatabaseBackend's methods for storage and retrieval, and adding some functions with Tome application logic that work with cached data.

Also, the name 'static' is really confusing here -- it's not a static cache, it's cached in the DB. It's a record of which site paths have been exported to the static copy of the site.

Steps to reproduce

Proposed resolution

What this should actually be is two things:

1. A cache bin.
2. A service which injects that cache bin.

A cache bin is just defined in services.yml like this:

  cache.entity:
    class: Drupal\Core\Cache\CacheBackendInterface
    tags:
      - { name: cache.bin }
    factory: ['@cache_factory', 'get']
    arguments: [entity]

You then inject it into a service, which makes the calls to $this->cache->get() etc.

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Active

Version

1.0

Component

Tome Static

Created by

🇬🇧United Kingdom joachim

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

Comments & Activities

Production build 0.71.5 2024