Introduction

Provides a base entity type and entity storage for storing entities in the cache instead of using the database.

Can be used for example when you want to temporarily store data that was retrieved by an API. To avoid calling that API all the time.

Usage

See the cache_entity_type_example module for examples.

Create an Entity class which uses the CacheEntityStorage class or a subclass of it as storage.

Either CacheEntityBase or ExtendedCacheEntityBase can be used as a base class. But don't have to. However the Entity Type must implement the CacheEntityInterface.

use Drupal\cache_entity_type\Entity\CacheEntityBase;

/**
 * Class DailyWeatherForecast.
 *
 * @EntityType(
 *   id = "example_daily_weather_forecast",
 *   label = @Translation("Weather forecast for a single day"),
 *   handlers = {
 *     "storage" = "Drupal\cache_entity_type\Entity\Cache\CacheEntityStorage",
 *   },
 *   render_cache = FALSE,
 *   entity_keys = {
 *     "id" = "id"
 *   },
 * )
 */
class DailyWeatherForecast extends CacheEntityBase {}

Installation

Install as you would normally install a contributed Drupal module. Visit: https://www.drupal.org/docs/8/extending-drupal-8/installing-drupal-8-modules for further information.

Requirements

  • This module requires Drupal ^8.8 or ^9.
  • PHP >= 7.4.
  • No additional modules are needed.
Supporting organizations: 
Initial development

Project information

Releases