diff --git a/core/core.services.yml b/core/core.services.yml index cbcccfe20c82a153098b8ff54c84034ef40fc265..c58c15d7bb8643ab6f978ecc91604036e9596e67 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -539,6 +539,8 @@ services: # @todo Remove this tag in https://www.drupal.org/node/2549143. tags: - { name: plugin_manager_cache_clear } + entity.memory_cache: + class: Drupal\Core\Cache\MemoryCache\MemoryCache entity_type.manager: class: Drupal\Core\Entity\EntityTypeManager arguments: ['@container.namespaces', '@module_handler', '@cache.discovery', '@string_translation', '@class_resolver'] diff --git a/core/lib/Drupal/Core/Cache/MemoryCache/MemoryCache.php b/core/lib/Drupal/Core/Cache/MemoryCache/MemoryCache.php new file mode 100644 index 0000000000000000000000000000000000000000..5ab540ede961c5222abf2d79ff53ddaf8d636aeb --- /dev/null +++ b/core/lib/Drupal/Core/Cache/MemoryCache/MemoryCache.php @@ -0,0 +1,62 @@ +data)) { + return FALSE; + } + // Check expire time. + $cache->valid = $cache->expire == static::CACHE_PERMANENT || $cache->expire >= $this->getRequestTime(); + + if (!$allow_invalid && !$cache->valid) { + return FALSE; + } + + return $cache; + } + + /** + * {@inheritdoc} + */ + public function set($cid, $data, $expire = MemoryCacheInterface::CACHE_PERMANENT, array $tags = []) { + assert('\Drupal\Component\Assertion\Inspector::assertAllStrings($tags)', 'Cache Tags must be strings.'); + $tags = array_unique($tags); + + $this->cache[$cid] = (object) [ + 'cid' => $cid, + 'data' => $data, + 'created' => $this->getRequestTime(), + 'expire' => $expire, + 'tags' => $tags, + ]; + } + +} diff --git a/core/lib/Drupal/Core/Cache/MemoryCache/MemoryCacheInterface.php b/core/lib/Drupal/Core/Cache/MemoryCache/MemoryCacheInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..c794ea10eaa0dfad645be7e48f429d404433e433 --- /dev/null +++ b/core/lib/Drupal/Core/Cache/MemoryCache/MemoryCacheInterface.php @@ -0,0 +1,18 @@ +configFactory = $config_factory; $this->uuidService = $uuid_service; @@ -121,7 +124,8 @@ public static function createInstance(ContainerInterface $container, EntityTypeI $entity_type, $container->get('config.factory'), $container->get('uuid'), - $container->get('language_manager') + $container->get('language_manager'), + $container->get('entity.memory_cache') ); } @@ -324,43 +328,10 @@ public function hasData() { } /** - * Gets entities from the static cache. - * - * @param array $ids - * If not empty, return entities that match these IDs. - * - * @return \Drupal\Core\Entity\EntityInterface[] - * Array of entities from the entity cache. - */ - protected function getFromStaticCache(array $ids) { - $entities = []; - // Load any available entities from the internal cache. - if ($this->entityType->isStaticallyCacheable() && !empty($this->entities)) { - $config_overrides_key = $this->overrideFree ? '' : implode(':', $this->configFactory->getCacheKeys()); - foreach ($ids as $id) { - if (!empty($this->entities[$id])) { - if (isset($this->entities[$id][$config_overrides_key])) { - $entities[$id] = $this->entities[$id][$config_overrides_key]; - } - } - } - } - return $entities; - } - - /** - * Stores entities in the static entity cache. - * - * @param \Drupal\Core\Entity\EntityInterface[] $entities - * Entities to store in the cache. - */ - protected function setStaticCache(array $entities) { - if ($this->entityType->isStaticallyCacheable()) { - $config_overrides_key = $this->overrideFree ? '' : implode(':', $this->configFactory->getCacheKeys()); - foreach ($entities as $id => $entity) { - $this->entities[$id][$config_overrides_key] = $entity; - } - } + * {@inheritdoc} + */ + protected function buildCacheId($id) { + return parent::buildCacheId($id) . ':' . ($this->overrideFree ? '' : implode(':', $this->configFactory->getCacheKeys())); } /** diff --git a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php index a004ebad8142fabee4c9e29145bc573f5e6a60a9..bc56c4271eb70fffba9f7e3235aa97384a3ced76 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php @@ -4,6 +4,7 @@ use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\TypedData\TranslationStatusInterface; @@ -44,9 +45,11 @@ abstract class ContentEntityStorageBase extends EntityStorageBase implements Con * The entity manager. * @param \Drupal\Core\Cache\CacheBackendInterface $cache * The cache backend to be used. + * @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface|null $memory_cache + * The memory cache backend. */ - public function __construct(EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, CacheBackendInterface $cache) { - parent::__construct($entity_type); + public function __construct(EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, CacheBackendInterface $cache, MemoryCacheInterface $memory_cache = NULL) { + parent::__construct($entity_type, $memory_cache); $this->bundleKey = $this->entityType->getKey('bundle'); $this->entityManager = $entity_manager; $this->cacheBackend = $cache; @@ -59,7 +62,8 @@ public static function createInstance(ContainerInterface $container, EntityTypeI return new static( $entity_type, $container->get('entity.manager'), - $container->get('cache.entity') + $container->get('cache.entity'), + $container->get('entity.memory_cache') ); } @@ -990,34 +994,21 @@ public function loadUnchanged($id) { */ public function resetCache(array $ids = NULL) { if ($ids) { - $cids = []; - foreach ($ids as $id) { - unset($this->entities[$id]); - $cids[] = $this->buildCacheId($id); - } + parent::resetCache($ids); if ($this->entityType->isPersistentlyCacheable()) { + $cids = []; + foreach ($ids as $id) { + $cids[] = $this->buildCacheId($id); + } $this->cacheBackend->deleteMultiple($cids); } } else { - $this->entities = []; + parent::resetCache(); if ($this->entityType->isPersistentlyCacheable()) { Cache::invalidateTags([$this->entityTypeId . '_values']); } } } - /** - * Builds the cache ID for the passed in entity ID. - * - * @param int $id - * Entity ID for which the cache ID should be built. - * - * @return string - * Cache ID that can be passed to the cache backend. - */ - protected function buildCacheId($id) { - return "values:{$this->entityTypeId}:$id"; - } - } diff --git a/core/lib/Drupal/Core/Entity/EntityStorageBase.php b/core/lib/Drupal/Core/Entity/EntityStorageBase.php index 58b0a3481cd0426f763f0cdc431a47ef04a9f69e..97e6657920b7dab13d160d9bcf7336f7e176a68b 100644 --- a/core/lib/Drupal/Core/Entity/EntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/EntityStorageBase.php @@ -3,19 +3,13 @@ namespace Drupal\Core\Entity; use Drupal\Core\Entity\Query\QueryInterface; +use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface; /** * A base entity storage class. */ abstract class EntityStorageBase extends EntityHandlerBase implements EntityStorageInterface, EntityHandlerInterface { - /** - * Static cache of entities, keyed by entity ID. - * - * @var array - */ - protected $entities = []; - /** * Entity type ID for this storage. * @@ -72,19 +66,42 @@ abstract class EntityStorageBase extends EntityHandlerBase implements EntityStor */ protected $entityClass; + /** + * The memory cache. + * + * @var \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface + */ + protected $memoryCache; + + /** + * The memory cache cache tag. + * + * @var string + */ + protected $memoryCacheTag; + /** * Constructs an EntityStorageBase instance. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type definition. + * @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface|null $memory_cache + * The memory cache. */ - public function __construct(EntityTypeInterface $entity_type) { + public function __construct(EntityTypeInterface $entity_type, MemoryCacheInterface $memory_cache = NULL) { $this->entityTypeId = $entity_type->id(); $this->entityType = $entity_type; $this->idKey = $this->entityType->getKey('id'); $this->uuidKey = $this->entityType->getKey('uuid'); $this->langcodeKey = $this->entityType->getKey('langcode'); $this->entityClass = $this->entityType->getClass(); + + if (!isset($memory_cache)) { + @trigger_error('The $memory_cache parameter was added in Drupal 8.6.x and will be required in 9.0.0. See https://www.drupal.org/node/2973262', E_USER_DEPRECATED); + $memory_cache = \Drupal::service('entity.memory_cache'); + } + $this->memoryCache = $memory_cache; + $this->memoryCacheTag = 'entity.memory_cache:' . $this->entityTypeId; } /** @@ -101,6 +118,19 @@ public function getEntityType() { return $this->entityType; } + /** + * Builds the cache ID for the passed in entity ID. + * + * @param int $id + * Entity ID for which the cache ID should be built. + * + * @return string + * Cache ID that can be passed to the cache backend. + */ + protected function buildCacheId($id) { + return "values:{$this->entityTypeId}:$id"; + } + /** * {@inheritdoc} */ @@ -115,11 +145,12 @@ public function loadUnchanged($id) { public function resetCache(array $ids = NULL) { if ($this->entityType->isStaticallyCacheable() && isset($ids)) { foreach ($ids as $id) { - unset($this->entities[$id]); + $this->memoryCache->delete($this->buildCacheId($id)); } } else { - $this->entities = []; + // Call the backend method directly. + $this->memoryCache->invalidateTags([$this->memoryCacheTag]); } } @@ -135,8 +166,12 @@ public function resetCache(array $ids = NULL) { protected function getFromStaticCache(array $ids) { $entities = []; // Load any available entities from the internal cache. - if ($this->entityType->isStaticallyCacheable() && !empty($this->entities)) { - $entities += array_intersect_key($this->entities, array_flip($ids)); + if ($this->entityType->isStaticallyCacheable()) { + foreach ($ids as $id) { + if ($cached = $this->memoryCache->get($this->buildCacheId($id))) { + $entities[$id] = $cached->data; + } + } } return $entities; } @@ -149,7 +184,9 @@ protected function getFromStaticCache(array $ids) { */ protected function setStaticCache(array $entities) { if ($this->entityType->isStaticallyCacheable()) { - $this->entities += $entities; + foreach ($entities as $id => $entity) { + $this->memoryCache->set($this->buildCacheId($entity->id()), $entity, MemoryCacheInterface::CACHE_PERMANENT, [$this->memoryCacheTag]); + } } } @@ -541,16 +578,4 @@ public function getAggregateQuery($conjunction = 'AND') { */ abstract protected function getQueryServiceName(); - /** - * {@inheritdoc} - */ - public function __sleep() { - // In case the storage is being serialized then we prevent from serializing - // the static cache of entities together with it, as this could lead to a - // memory leak. - $vars = parent::__sleep(); - unset($vars['entities']); - return $vars; - } - } diff --git a/core/lib/Drupal/Core/Entity/EntityTypeManager.php b/core/lib/Drupal/Core/Entity/EntityTypeManager.php index abe96a5c264e8e64832dccbd95dc1cea8bee6c89..9d7fdc5e9294141e8d040cd79c4ad71c223aa053 100644 --- a/core/lib/Drupal/Core/Entity/EntityTypeManager.php +++ b/core/lib/Drupal/Core/Entity/EntityTypeManager.php @@ -148,6 +148,7 @@ public function useCaches($use_caches = FALSE) { parent::useCaches($use_caches); if (!$use_caches) { $this->handlers = []; + $this->container->get('entity.memory_cache')->reset(); } } diff --git a/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php b/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php index cd2f26efbd695a6d9720ea0ceea65a861576586e..113f6307873bdc37d52959d1345f7a6735795704 100644 --- a/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php @@ -3,6 +3,7 @@ namespace Drupal\Core\Entity\KeyValueStore; use Drupal\Component\Uuid\UuidInterface; +use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface; use Drupal\Core\Config\Entity\Exception\ConfigEntityIdLengthException; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\EntityInterface; @@ -60,9 +61,11 @@ class KeyValueEntityStorage extends EntityStorageBase { * The UUID service. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. + * @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface $memory_cache + * The memory cache. */ - public function __construct(EntityTypeInterface $entity_type, KeyValueStoreInterface $key_value_store, UuidInterface $uuid_service, LanguageManagerInterface $language_manager) { - parent::__construct($entity_type); + public function __construct(EntityTypeInterface $entity_type, KeyValueStoreInterface $key_value_store, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, MemoryCacheInterface $memory_cache = NULL) { + parent::__construct($entity_type, $memory_cache); $this->keyValueStore = $key_value_store; $this->uuidService = $uuid_service; $this->languageManager = $language_manager; @@ -79,7 +82,8 @@ public static function createInstance(ContainerInterface $container, EntityTypeI $entity_type, $container->get('keyvalue')->get('entity_storage__' . $entity_type->id()), $container->get('uuid'), - $container->get('language_manager') + $container->get('language_manager'), + $container->get('entity.memory_cache') ); } diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php index 3fefd5e763fd713235ea50b73748c70297ff91cf..dfae89736329739f036a98e587e14c9b2b758511 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php @@ -3,6 +3,7 @@ namespace Drupal\Core\Entity\Sql; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface; use Drupal\Core\Database\Connection; use Drupal\Core\Database\Database; use Drupal\Core\Database\DatabaseExceptionWrapper; @@ -132,7 +133,8 @@ public static function createInstance(ContainerInterface $container, EntityTypeI $container->get('database'), $container->get('entity.manager'), $container->get('cache.entity'), - $container->get('language_manager') + $container->get('language_manager'), + $container->get('entity.memory_cache') ); } @@ -160,9 +162,11 @@ public function getFieldStorageDefinitions() { * The cache backend to be used. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. + * @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface|null $memory_cache + * The memory cache backend to be used. */ - public function __construct(EntityTypeInterface $entity_type, Connection $database, EntityManagerInterface $entity_manager, CacheBackendInterface $cache, LanguageManagerInterface $language_manager) { - parent::__construct($entity_type, $entity_manager, $cache); + public function __construct(EntityTypeInterface $entity_type, Connection $database, EntityManagerInterface $entity_manager, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, MemoryCacheInterface $memory_cache = NULL) { + parent::__construct($entity_type, $entity_manager, $cache, $memory_cache); $this->database = $database; $this->languageManager = $language_manager; $this->initTableLayout(); diff --git a/core/lib/Drupal/Core/Field/BaseFieldOverrideStorage.php b/core/lib/Drupal/Core/Field/BaseFieldOverrideStorage.php index 744e585d14c00bac70de65b0c2e80955164261e3..7bf872bfc7be6538f60f88afcb7d550b2fa22c4e 100644 --- a/core/lib/Drupal/Core/Field/BaseFieldOverrideStorage.php +++ b/core/lib/Drupal/Core/Field/BaseFieldOverrideStorage.php @@ -2,6 +2,7 @@ namespace Drupal\Core\Field; +use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Language\LanguageManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -26,9 +27,11 @@ class BaseFieldOverrideStorage extends FieldConfigStorageBase { * The language manager. * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager * The field type plugin manager. + * @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface $memory_cache + * The memory cache. */ - public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, FieldTypePluginManagerInterface $field_type_manager) { - parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager); + public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, FieldTypePluginManagerInterface $field_type_manager, MemoryCacheInterface $memory_cache) { + parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager, $memory_cache); $this->fieldTypeManager = $field_type_manager; } @@ -41,7 +44,8 @@ public static function createInstance(ContainerInterface $container, EntityTypeI $container->get('config.factory'), $container->get('uuid'), $container->get('language_manager'), - $container->get('plugin.manager.field.field_type') + $container->get('plugin.manager.field.field_type'), + $container->get('entity.memory_cache') ); } diff --git a/core/modules/comment/src/CommentStorage.php b/core/modules/comment/src/CommentStorage.php index 2bcda91d003b3635bd093eba40c4ce2cf5d44088..33243743a64f4c0092d60093e16d4c93940a936a 100644 --- a/core/modules/comment/src/CommentStorage.php +++ b/core/modules/comment/src/CommentStorage.php @@ -3,6 +3,7 @@ namespace Drupal\comment; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface; use Drupal\Core\Database\Connection; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityTypeInterface; @@ -43,9 +44,11 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn * Cache backend instance to use. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. + * @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface $memory_cache + * The memory cache. */ - public function __construct(EntityTypeInterface $entity_info, Connection $database, EntityManagerInterface $entity_manager, AccountInterface $current_user, CacheBackendInterface $cache, LanguageManagerInterface $language_manager) { - parent::__construct($entity_info, $database, $entity_manager, $cache, $language_manager); + public function __construct(EntityTypeInterface $entity_info, Connection $database, EntityManagerInterface $entity_manager, AccountInterface $current_user, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, MemoryCacheInterface $memory_cache) { + parent::__construct($entity_info, $database, $entity_manager, $cache, $language_manager, $memory_cache); $this->currentUser = $current_user; } @@ -59,7 +62,8 @@ public static function createInstance(ContainerInterface $container, EntityTypeI $container->get('entity.manager'), $container->get('current_user'), $container->get('cache.entity'), - $container->get('language_manager') + $container->get('language_manager'), + $container->get('entity.memory_cache') ); } diff --git a/core/modules/field/src/FieldConfigStorage.php b/core/modules/field/src/FieldConfigStorage.php index a0e460f00f9c74d82c13c37a39f12ee1b9e6e46b..2794674bddb985cb1d153c0a9839c61eced9579e 100644 --- a/core/modules/field/src/FieldConfigStorage.php +++ b/core/modules/field/src/FieldConfigStorage.php @@ -2,6 +2,7 @@ namespace Drupal\field; +use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface; use Drupal\Core\Config\Config; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityTypeInterface; @@ -56,9 +57,11 @@ class FieldConfigStorage extends FieldConfigStorageBase { * The field type plugin manager. * @param \Drupal\Core\Field\DeletedFieldsRepositoryInterface $deleted_fields_repository * The deleted fields repository. + * @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface $memory_cache + * The memory cache. */ - public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, DeletedFieldsRepositoryInterface $deleted_fields_repository) { - parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager); + public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, DeletedFieldsRepositoryInterface $deleted_fields_repository, MemoryCacheInterface $memory_cache) { + parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager, $memory_cache); $this->entityManager = $entity_manager; $this->fieldTypeManager = $field_type_manager; $this->deletedFieldsRepository = $deleted_fields_repository; @@ -75,7 +78,8 @@ public static function createInstance(ContainerInterface $container, EntityTypeI $container->get('language_manager'), $container->get('entity.manager'), $container->get('plugin.manager.field.field_type'), - $container->get('entity_field.deleted_fields_repository') + $container->get('entity_field.deleted_fields_repository'), + $container->get('entity.memory_cache') ); } diff --git a/core/modules/field/src/FieldStorageConfigStorage.php b/core/modules/field/src/FieldStorageConfigStorage.php index 3c3d8d8e3f33ca3ce849a4894c52707e89f8ea84..4d23c9eedbb860d15ecbebac06f59d08dd40bd95 100644 --- a/core/modules/field/src/FieldStorageConfigStorage.php +++ b/core/modules/field/src/FieldStorageConfigStorage.php @@ -3,6 +3,7 @@ namespace Drupal\field; use Drupal\Component\Uuid\UuidInterface; +use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface; use Drupal\Core\Config\Entity\ConfigEntityStorage; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManagerInterface; @@ -66,9 +67,11 @@ class FieldStorageConfigStorage extends ConfigEntityStorage { * The field type plugin manager. * @param \Drupal\Core\Field\DeletedFieldsRepositoryInterface $deleted_fields_repository * The deleted fields repository. + * @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface $memory_cache + * The memory cache. */ - public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, FieldTypePluginManagerInterface $field_type_manager, DeletedFieldsRepositoryInterface $deleted_fields_repository) { - parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager); + public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, FieldTypePluginManagerInterface $field_type_manager, DeletedFieldsRepositoryInterface $deleted_fields_repository, MemoryCacheInterface $memory_cache) { + parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager, $memory_cache); $this->entityManager = $entity_manager; $this->moduleHandler = $module_handler; $this->fieldTypeManager = $field_type_manager; @@ -87,7 +90,8 @@ public static function createInstance(ContainerInterface $container, EntityTypeI $container->get('entity.manager'), $container->get('module_handler'), $container->get('plugin.manager.field.field_type'), - $container->get('entity_field.deleted_fields_repository') + $container->get('entity_field.deleted_fields_repository'), + $container->get('entity.memory_cache') ); } diff --git a/core/modules/shortcut/src/ShortcutSetStorage.php b/core/modules/shortcut/src/ShortcutSetStorage.php index b136c2fb07dbf6f8b4d2437f4c925bb2115ecb65..ecb3472c0c64a5c0a4910d1e1aea2994cac7dfbc 100644 --- a/core/modules/shortcut/src/ShortcutSetStorage.php +++ b/core/modules/shortcut/src/ShortcutSetStorage.php @@ -3,6 +3,7 @@ namespace Drupal\shortcut; use Drupal\Component\Uuid\UuidInterface; +use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\Entity\ConfigEntityStorage; use Drupal\Core\Entity\EntityTypeInterface; @@ -36,9 +37,11 @@ class ShortcutSetStorage extends ConfigEntityStorage implements ShortcutSetStora * The module handler. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. + * @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface $memory_cache + * The memory cache. */ - public function __construct(EntityTypeInterface $entity_info, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager) { - parent::__construct($entity_info, $config_factory, $uuid_service, $language_manager); + public function __construct(EntityTypeInterface $entity_info, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager, MemoryCacheInterface $memory_cache) { + parent::__construct($entity_info, $config_factory, $uuid_service, $language_manager, $memory_cache); $this->moduleHandler = $module_handler; } @@ -52,7 +55,8 @@ public static function createInstance(ContainerInterface $container, EntityTypeI $container->get('config.factory'), $container->get('uuid'), $container->get('module_handler'), - $container->get('language_manager') + $container->get('language_manager'), + $container->get('entity.memory_cache') ); } diff --git a/core/modules/user/tests/src/Functional/Update/UserUpdateOrderPermissionsTest.php b/core/modules/user/tests/src/Functional/Update/UserUpdateOrderPermissionsTest.php index 4d6e7f960096e6451414327693ee68c7eb186504..b6837ed78b23c53e16c1c08eaa2ecc713803da0c 100644 --- a/core/modules/user/tests/src/Functional/Update/UserUpdateOrderPermissionsTest.php +++ b/core/modules/user/tests/src/Functional/Update/UserUpdateOrderPermissionsTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\user\Functional\Update; use Drupal\FunctionalTests\Update\UpdatePathTestBase; -use Drupal\user\Entity\Role; /** * Tests user permissions sort upgrade path. @@ -25,14 +24,14 @@ protected function setDatabaseDumpFiles() { * Tests that permissions are ordered by machine name. */ public function testPermissionsOrder() { - $authenticated = Role::load('authenticated'); - $permissions = $authenticated->getPermissions(); + $authenticated = \Drupal::config('user.role.authenticated'); + $permissions = $authenticated->get('permissions'); sort($permissions); - $this->assertNotIdentical($permissions, $authenticated->getPermissions()); + $this->assertNotSame($permissions, $authenticated->get('permissions')); $this->runUpdates(); - $authenticated = Role::load('authenticated'); - $this->assertIdentical($permissions, $authenticated->getPermissions()); + $authenticated = \Drupal::config('user.role.authenticated'); + $this->assertSame($permissions, $authenticated->get('permissions')); } } diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php index 3d86ecd11268d1f7ede06ff8975805630d5bc505..1cf57dfa5c1377789a13e7e90c8fc160bd79d803 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php @@ -5,6 +5,7 @@ use Drupal\Component\Uuid\UuidInterface; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheTagsInvalidatorInterface; +use Drupal\Core\Cache\MemoryCache\MemoryCache; use Drupal\Core\Config\Config; use Drupal\Core\Config\ConfigDuplicateUUIDException; use Drupal\Core\Config\ConfigFactoryInterface; @@ -133,7 +134,7 @@ protected function setUp() { $entity_query_factory = $this->prophesize(QueryFactoryInterface::class); $entity_query_factory->get($entity_type, 'AND')->willReturn($this->entityQuery->reveal()); - $this->entityStorage = new ConfigEntityStorage($entity_type, $this->configFactory->reveal(), $this->uuidService->reveal(), $this->languageManager->reveal()); + $this->entityStorage = new ConfigEntityStorage($entity_type, $this->configFactory->reveal(), $this->uuidService->reveal(), $this->languageManager->reveal(), new MemoryCache()); $this->entityStorage->setModuleHandler($this->moduleHandler->reveal()); $entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class); diff --git a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php index 846ce0a59f2f1305f4fe21808fc2952c2d3988be..32d043da9eb06964778a110a4b66d8cba621daa3 100644 --- a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\Core\Entity\KeyValueStore; +use Drupal\Core\Cache\MemoryCache\MemoryCache; use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Entity\EntityFieldManagerInterface; @@ -143,7 +144,7 @@ protected function setUpKeyValueEntityStorage($uuid_key = 'uuid') { ->method('getCurrentLanguage') ->will($this->returnValue($language)); - $this->entityStorage = new KeyValueEntityStorage($this->entityType, $this->keyValueStore, $this->uuidService, $this->languageManager); + $this->entityStorage = new KeyValueEntityStorage($this->entityType, $this->keyValueStore, $this->uuidService, $this->languageManager, new MemoryCache()); $this->entityStorage->setModuleHandler($this->moduleHandler); $container = new ContainerBuilder(); diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php index 3d7fb43aef190901f757b73d4aecfe0a741a2363..c9359bd9b8a7dfa68129d40e2babfa679d3b8919 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php @@ -8,6 +8,7 @@ namespace Drupal\Tests\Core\Entity\Sql; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Cache\MemoryCache\MemoryCache; use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManager; @@ -378,7 +379,7 @@ public function testOnEntityTypeCreate() { ->will($this->returnValue($schema_handler)); $storage = $this->getMockBuilder('Drupal\Core\Entity\Sql\SqlContentEntityStorage') - ->setConstructorArgs([$this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager]) + ->setConstructorArgs([$this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager, new MemoryCache()]) ->setMethods(['getStorageSchema']) ->getMock(); @@ -1123,7 +1124,7 @@ protected function setUpEntityStorage() { ->method('getBaseFieldDefinitions') ->will($this->returnValue($this->fieldDefinitions)); - $this->entityStorage = new SqlContentEntityStorage($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager); + $this->entityStorage = new SqlContentEntityStorage($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager, new MemoryCache()); } /** @@ -1198,7 +1199,7 @@ public function testLoadMultipleNoPersistentCache() { ->method('set'); $entity_storage = $this->getMockBuilder('Drupal\Core\Entity\Sql\SqlContentEntityStorage') - ->setConstructorArgs([$this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager]) + ->setConstructorArgs([$this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager, new MemoryCache()]) ->setMethods(['getFromStorage', 'invokeStorageLoadHook']) ->getMock(); $entity_storage->method('invokeStorageLoadHook') @@ -1250,7 +1251,7 @@ public function testLoadMultiplePersistentCacheMiss() { ->with($key, $entity, CacheBackendInterface::CACHE_PERMANENT, [$this->entityTypeId . '_values', 'entity_field_info']); $entity_storage = $this->getMockBuilder('Drupal\Core\Entity\Sql\SqlContentEntityStorage') - ->setConstructorArgs([$this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager]) + ->setConstructorArgs([$this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager, new MemoryCache()]) ->setMethods(['getFromStorage', 'invokeStorageLoadHook']) ->getMock(); $entity_storage->method('invokeStorageLoadHook') @@ -1305,7 +1306,7 @@ public function testHasData() { ->method('getBaseFieldDefinitions') ->will($this->returnValue($this->fieldDefinitions)); - $this->entityStorage = new SqlContentEntityStorage($this->entityType, $database, $this->entityManager, $this->cache, $this->languageManager); + $this->entityStorage = new SqlContentEntityStorage($this->entityType, $database, $this->entityManager, $this->cache, $this->languageManager, new MemoryCache()); $result = $this->entityStorage->hasData(); diff --git a/core/tests/Drupal/Tests/Core/Session/UserSessionTest.php b/core/tests/Drupal/Tests/Core/Session/UserSessionTest.php index 85fe1bbf36dec068aff075ad6145d7c5f078ad9d..4ae51829035788113e5f1370395470cb24dc12e5 100644 --- a/core/tests/Drupal/Tests/Core/Session/UserSessionTest.php +++ b/core/tests/Drupal/Tests/Core/Session/UserSessionTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\Core\Session; +use Drupal\Core\Cache\MemoryCache\MemoryCache; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Session\UserSession; use Drupal\Tests\UnitTestCase; @@ -94,6 +95,7 @@ protected function setUp() { ])); $role_storage = $this->getMockBuilder('Drupal\user\RoleStorage') + ->setConstructorArgs(['role', new MemoryCache()]) ->disableOriginalConstructor() ->setMethods(['loadMultiple']) ->getMock();