Issue #1596472 by catch, amateescu, claudiu.cristea, Berdir, Mile23, Sam152, pounard, fago, alexpott, fubhy, hchonov: Replace hard coded static cache of entities with cache backends
parent
d286720d56
commit
d8029d7ee0
|
@ -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']
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Core\Cache\MemoryCache;
|
||||
|
||||
use Drupal\Core\Cache\MemoryBackend;
|
||||
|
||||
/**
|
||||
* Defines a memory cache implementation.
|
||||
*
|
||||
* Stores cache items in memory using a PHP array.
|
||||
*
|
||||
* @ingroup cache
|
||||
*/
|
||||
class MemoryCache extends MemoryBackend implements MemoryCacheInterface {
|
||||
|
||||
/**
|
||||
* Prepares a cached item.
|
||||
*
|
||||
* Checks that items are either permanent or did not expire, and returns data
|
||||
* as appropriate.
|
||||
*
|
||||
* @param object $cache
|
||||
* An item loaded from cache_get() or cache_get_multiple().
|
||||
* @param bool $allow_invalid
|
||||
* (optional) If TRUE, cache items may be returned even if they have expired
|
||||
* or been invalidated. Defaults to FALSE.
|
||||
*
|
||||
* @return mixed
|
||||
* The item with data as appropriate or FALSE if there is no
|
||||
* valid item to load.
|
||||
*/
|
||||
protected function prepareItem($cache, $allow_invalid = FALSE) {
|
||||
if (!isset($cache->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,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Core\Cache\MemoryCache;
|
||||
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Cache\CacheTagsInvalidatorInterface;
|
||||
|
||||
/**
|
||||
* Defines an interface for memory cache implementations.
|
||||
*
|
||||
* This has additional requirements over CacheBackendInterface and
|
||||
* CacheTagsInvalidatorInterface. Objects stored must be the same instance when
|
||||
* retrieved from cache, so that this can be used as a replacement for protected
|
||||
* properties and similar.
|
||||
*
|
||||
* @ingroup cache
|
||||
*/
|
||||
interface MemoryCacheInterface extends CacheBackendInterface, CacheTagsInvalidatorInterface {}
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\Core\Config\Entity;
|
||||
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface;
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\Config\ConfigImporterException;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
|
@ -104,9 +105,11 @@ class ConfigEntityStorage extends EntityStorageBase implements ConfigEntityStora
|
|||
* The UUID service.
|
||||
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
|
||||
* The language manager.
|
||||
* @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface|null $memory_cache
|
||||
* The memory cache backend.
|
||||
*/
|
||||
public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager) {
|
||||
parent::__construct($entity_type);
|
||||
public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, MemoryCacheInterface $memory_cache = NULL) {
|
||||
parent::__construct($entity_type, $memory_cache);
|
||||
|
||||
$this->configFactory = $config_factory;
|
||||
$this->uuidService = $uuid_service;
|
||||
|
@ -121,7 +124,8 @@ class ConfigEntityStorage extends EntityStorageBase implements ConfigEntityStora
|
|||
$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 @@ class ConfigEntityStorage extends EntityStorageBase implements ConfigEntityStora
|
|||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
protected function buildCacheId($id) {
|
||||
return parent::buildCacheId($id) . ':' . ($this->overrideFree ? '' : implode(':', $this->configFactory->getCacheKeys()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Drupal\Core\Entity;
|
|||
|
||||
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 @@ abstract class ContentEntityStorageBase extends EntityStorageBase implements Con
|
|||
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 @@ abstract class ContentEntityStorageBase extends EntityStorageBase implements Con
|
|||
*/
|
||||
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";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 @@ abstract class EntityStorageBase extends EntityHandlerBase implements EntityStor
|
|||
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 @@ abstract class EntityStorageBase extends EntityHandlerBase implements EntityStor
|
|||
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 @@ abstract class EntityStorageBase extends EntityHandlerBase implements EntityStor
|
|||
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 @@ abstract class EntityStorageBase extends EntityHandlerBase implements EntityStor
|
|||
*/
|
||||
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 @@ abstract class EntityStorageBase extends EntityHandlerBase implements EntityStor
|
|||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -148,6 +148,7 @@ class EntityTypeManager extends DefaultPluginManager implements EntityTypeManage
|
|||
parent::useCaches($use_caches);
|
||||
if (!$use_caches) {
|
||||
$this->handlers = [];
|
||||
$this->container->get('entity.memory_cache')->reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 @@ class KeyValueEntityStorage extends EntityStorageBase {
|
|||
$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')
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt
|
|||
$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 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt
|
|||
* 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();
|
||||
|
|
|
@ -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 @@ class BaseFieldOverrideStorage extends FieldConfigStorageBase {
|
|||
$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')
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
|
|||
$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')
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 @@ class FieldConfigStorage extends FieldConfigStorageBase {
|
|||
$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')
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 @@ class FieldStorageConfigStorage extends ConfigEntityStorage {
|
|||
$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')
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 @@ class ShortcutSetStorage extends ConfigEntityStorage implements ShortcutSetStora
|
|||
$container->get('config.factory'),
|
||||
$container->get('uuid'),
|
||||
$container->get('module_handler'),
|
||||
$container->get('language_manager')
|
||||
$container->get('language_manager'),
|
||||
$container->get('entity.memory_cache')
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 @@ class UserUpdateOrderPermissionsTest extends UpdatePathTestBase {
|
|||
* 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'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Drupal\Tests\Core\Config\Entity;
|
|||
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 @@ class ConfigEntityStorageTest extends UnitTestCase {
|
|||
$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);
|
||||
|
|
|
@ -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 @@ class KeyValueEntityStorageTest extends UnitTestCase {
|
|||
->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();
|
||||
|
|
|
@ -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 @@ class SqlContentEntityStorageTest extends UnitTestCase {
|
|||
->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 @@ class SqlContentEntityStorageTest extends UnitTestCase {
|
|||
->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 @@ class SqlContentEntityStorageTest extends UnitTestCase {
|
|||
->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 @@ class SqlContentEntityStorageTest extends UnitTestCase {
|
|||
->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 @@ class SqlContentEntityStorageTest extends UnitTestCase {
|
|||
->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();
|
||||
|
||||
|
|
|
@ -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 @@ class UserSessionTest extends UnitTestCase {
|
|||
]));
|
||||
|
||||
$role_storage = $this->getMockBuilder('Drupal\user\RoleStorage')
|
||||
->setConstructorArgs(['role', new MemoryCache()])
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['loadMultiple'])
|
||||
->getMock();
|
||||
|
|
Loading…
Reference in New Issue