From 77d9bd38c150db6a54c7245612589eac0c50a79a Mon Sep 17 00:00:00 2001 From: Andrey Maximov Date: Tue, 16 May 2023 19:44:40 +0200 Subject: [PATCH] Free entity.memory_cache so that it doesn't consume too much memory --- openy_repeat.services.yml | 2 +- src/OpenyRepeatRepository.php | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/openy_repeat.services.yml b/openy_repeat.services.yml index c8f44994..b197fc3b 100644 --- a/openy_repeat.services.yml +++ b/openy_repeat.services.yml @@ -5,4 +5,4 @@ services: - { name: pdf_generator } openy_repeat.repository: class: Drupal\openy_repeat\OpenyRepeatRepository - arguments: ['@entity_type.manager', '@config.factory', '@cache.default'] + arguments: ['@entity_type.manager', '@config.factory', '@cache.default', '@entity.memory_cache'] diff --git a/src/OpenyRepeatRepository.php b/src/OpenyRepeatRepository.php index 98d89be5..ebd18e32 100644 --- a/src/OpenyRepeatRepository.php +++ b/src/OpenyRepeatRepository.php @@ -4,6 +4,7 @@ use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface; use Drupal\Core\Cache\UseCacheBackendTrait; use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Entity\EntityTypeManager; @@ -47,15 +48,18 @@ class OpenyRepeatRepository implements OpenyRepeatRepositoryInterface { * ConfigFactory. * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend * The cache backend. + * @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface $memory_cache + * The memory cache. * * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException */ - public function __construct(EntityTypeManager $entity_type_manager, ConfigFactory $configFactory, CacheBackendInterface $cache_backend) { + public function __construct(EntityTypeManager $entity_type_manager, ConfigFactory $configFactory, CacheBackendInterface $cache_backend, MemoryCacheInterface $memory_cache) { $this->entityTypeManager = $entity_type_manager; $this->configFactory = $configFactory; $this->cacheBackend = $cache_backend; $this->nodeStorage = $this->entityTypeManager->getStorage('node'); + $this->memoryCache = $memory_cache; } /** @@ -130,6 +134,7 @@ public function getLocationsIds() { $locationId = $session->get('field_session_location')->getString(); $locationsIds[$locationId] = $locationId; } + $this->memoryCache->deleteAll(); } return $locationsIds; }