diff --git a/core/core.services.yml b/core/core.services.yml index 6310c21..e934e48 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -202,7 +202,6 @@ services: tags: - { name: cache.bin, default_backend: cache.backend.memory } factory: cache_factory:get - arguments: [static] cache.bootstrap: class: Drupal\Core\Cache\CacheBackendInterface tags: @@ -1639,3 +1638,5 @@ services: class: Drupal\Core\EventSubscriber\RssResponseRelativeUrlFilter tags: - { name: event_subscriber } + static_cache: + class: Drupal\Core\Cache\StaticCache\StaticCache diff --git a/core/lib/Drupal/Core/Cache/CacheFactory.php b/core/lib/Drupal/Core/Cache/CacheFactory.php index 1d954f8..d9b39e4 100644 --- a/core/lib/Drupal/Core/Cache/CacheFactory.php +++ b/core/lib/Drupal/Core/Cache/CacheFactory.php @@ -72,6 +72,7 @@ public function get($bin) { elseif (isset($this->defaultBinBackends[$bin])) { $service_name = $this->defaultBinBackends[$bin]; } + // Third, use configured default backend. elseif (isset($cache_settings['default'])) { $service_name = $cache_settings['default']; } diff --git a/core/lib/Drupal/Core/Cache/MemoryBackend.php b/core/lib/Drupal/Core/Cache/MemoryBackend.php index a0d32bd..c517fb4 100644 --- a/core/lib/Drupal/Core/Cache/MemoryBackend.php +++ b/core/lib/Drupal/Core/Cache/MemoryBackend.php @@ -20,15 +20,6 @@ class MemoryBackend implements CacheBackendInterface, CacheTagsInvalidatorInterf protected $cache = array(); /** - * Constructs a MemoryBackend object. - * - * @param string $bin - * The cache bin for which the object is created. - */ - public function __construct($bin) { - } - - /** * {@inheritdoc} */ public function get($cid, $allow_invalid = FALSE) { diff --git a/core/lib/Drupal/Core/Cache/MemoryBackendFactory.php b/core/lib/Drupal/Core/Cache/MemoryBackendFactory.php index 221ee1a..4457e59 100644 --- a/core/lib/Drupal/Core/Cache/MemoryBackendFactory.php +++ b/core/lib/Drupal/Core/Cache/MemoryBackendFactory.php @@ -16,7 +16,7 @@ class MemoryBackendFactory implements CacheFactoryInterface { */ function get($bin) { if (!isset($this->bins[$bin])) { - $this->bins[$bin] = new MemoryBackend($bin); + $this->bins[$bin] = new MemoryBackend(); } return $this->bins[$bin]; } diff --git a/core/lib/Drupal/Core/Cache/Static/StaticCache.php b/core/lib/Drupal/Core/Cache/StaticCache/StaticCache.php similarity index 95% rename from core/lib/Drupal/Core/Cache/Static/StaticCache.php rename to core/lib/Drupal/Core/Cache/StaticCache/StaticCache.php index cabc8a1..ee47756 100644 --- a/core/lib/Drupal/Core/Cache/Static/StaticCache.php +++ b/core/lib/Drupal/Core/Cache/StaticCache/StaticCache.php @@ -1,6 +1,8 @@ configFactory = $config_factory; $this->uuidService = $uuid_service; diff --git a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php index 84d8411..753d745 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\StaticCache\StaticCacheInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -46,8 +47,8 @@ * @param \Drupal\Core\Cache\CacheBackendInterface $static_cache * The cache backend to be used. */ - public function __construct(EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, CacheBackendInterface $cache, CacheBackendInterface $static_cache = NULL) { - $static_cache = isset($static_cache) ? $static_cache : \Drupal::service('cache.static'); + public function __construct(EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, CacheBackendInterface $cache, StaticCacheInterface $static_cache = NULL) { + $static_cache = isset($static_cache) ? $static_cache : \Drupal::service('static_cache'); parent::__construct($entity_type, $static_cache); $this->bundleKey = $this->entityType->getKey('bundle'); $this->entityManager = $entity_manager; @@ -61,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('static_cache') ); } diff --git a/core/lib/Drupal/Core/Entity/EntityStorageBase.php b/core/lib/Drupal/Core/Entity/EntityStorageBase.php index 6a3b13f..39fc525 100644 --- a/core/lib/Drupal/Core/Entity/EntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/EntityStorageBase.php @@ -3,8 +3,8 @@ namespace Drupal\Core\Entity; use Drupal\Core\Entity\Query\QueryInterface; -use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Cache\Cache; +use Drupal\Core\Cache\StaticCache\StaticCacheInterface; /** * A base entity storage class. @@ -75,28 +75,28 @@ protected $entityClass; /** - * The static cache backend. + * The static cache. * - * @var \Drupal\Core\Cache\CacheBackendInterface + * @var \Drupal\Core\StaticCache\StaticCacheInterface */ - protected $staticCacheBackend; + protected $staticCache; /** * Constructs an EntityStorageBase instance. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type definition. - * @param \Drupal\Core\Cache\CacheBackendInterface - * The static cache backend. + * @param \Drupal\Core\Cache\StaticCache\StaticCacheInterface + * The static cache. */ - public function __construct(EntityTypeInterface $entity_type, CacheBackendInterface $static_cache_backend = NULL) { + public function __construct(EntityTypeInterface $entity_type, StaticCacheInterface $static_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(); - $this->staticCacheBackend = isset($static_cache_backend) ? $static_cache_backend : \Drupal::service('cache.static'); + $this->staticCache = isset($static_cache) ? $static_cache : \Drupal::service('static_cache'); } /** @@ -134,12 +134,12 @@ public function loadUnchanged($id) { public function resetCache(array $ids = NULL) { if ($this->entityType->isStaticallyCacheable() && isset($ids)) { foreach ($ids as $id) { - $this->staticCacheBackend->delete($this->getCacheId($id)); + $this->staticCache->delete($this->getCacheId($id)); } } else { // Call the backend method directly. - $this->staticCacheBackend->invalidateTags(['entity_static_cache']); + $this->staticCache->invalidateTags(['entity_static_cache']); } } @@ -157,7 +157,7 @@ protected function getFromStaticCache(array $ids) { // Load any available entities from the internal cache. if ($this->entityType->isStaticallyCacheable()) { foreach ($ids as $id) { - if ($cached = $this->staticCacheBackend->get($this->getCacheId($id))) { + if ($cached = $this->staticCache->get($this->getCacheId($id))) { $entities[$id] = $cached->data; } } @@ -174,7 +174,7 @@ protected function getFromStaticCache(array $ids) { protected function setStaticCache(array $entities) { if ($this->entityType->isStaticallyCacheable()) { foreach ($entities as $id => $entity) { - $this->staticCacheBackend->set($this->getCacheId($entity->id()), $entity, CacheBackendInterface::CACHE_PERMANENT, ['entity_static_cache']); + $this->staticCache->set($this->getCacheId($entity->id()), $entity, $this->staticCache::CACHE_PERMANENT, ['entity_static_cache']); } } } diff --git a/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php b/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php index 1f9abde..395414d 100644 --- a/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php @@ -3,7 +3,7 @@ namespace Drupal\Core\Entity\KeyValueStore; use Drupal\Component\Uuid\UuidInterface; -use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Cache\StaticCache\StaticCacheInterface; use Drupal\Core\Config\Entity\Exception\ConfigEntityIdLengthException; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\EntityInterface; @@ -51,11 +51,11 @@ class KeyValueEntityStorage extends EntityStorageBase { protected $languageManager; /** - * The memory cache backend. + * The static cache. * - * @var \Drupal\Core\Cache\CacheBackendInterface + * @var \Drupal\Core\StaticCache\StaticCacheInterface */ - protected $staticCacheBackend; + protected $staticCache; /** * Constructs a new KeyValueEntityStorage. @@ -68,12 +68,12 @@ class KeyValueEntityStorage extends EntityStorageBase { * The UUID service. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. - * @param \Drupal\Core\Cache\CacheBackendInterface $static_cache_backend - * The static cache backend. + * @param \Drupal\Core\StaticCache\StaticCacheInterface $static_cache + * The static cache. */ - public function __construct(EntityTypeInterface $entity_type, KeyValueStoreInterface $key_value_store, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, CacheBackendInterface $static_cache_backend = NULL) { - $static_cache_backend = isset($static_cache_backend) ? $static_cache_backend : \Drupal::service('cache.static'); - parent::__construct($entity_type, $static_cache_backend); + public function __construct(EntityTypeInterface $entity_type, KeyValueStoreInterface $key_value_store, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, StaticCacheInterface $static_cache = NULL) { + $static_cache = isset($static_cache) ? $static_cache : \Drupal::service('static_cache'); + parent::__construct($entity_type, $static_cache); $this->keyValueStore = $key_value_store; $this->uuidService = $uuid_service; $this->languageManager = $language_manager; diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php index f9e7687..f35ed95 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php @@ -127,7 +127,7 @@ public static function createInstance(ContainerInterface $container, EntityTypeI $container->get('entity.manager'), $container->get('cache.entity'), $container->get('language_manager'), - $container->get('cache.static') + $container->get('static_cache') ); } @@ -159,7 +159,7 @@ public function getFieldStorageDefinitions() { * The static cache backend to be used. */ public function __construct(EntityTypeInterface $entity_type, Connection $database, EntityManagerInterface $entity_manager, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, CacheBackendInterface $static_cache = NULL) { - $static_cache = isset($static_cache) ? $static_cache : \Drupal::service('cache.static'); + $static_cache = isset($static_cache) ? $static_cache : \Drupal::service('static_cache'); parent::__construct($entity_type, $entity_manager, $cache, $static_cache); $this->database = $database; $this->languageManager = $language_manager; diff --git a/core/tests/Drupal/KernelTests/Core/Command/DbDumpTest.php b/core/tests/Drupal/KernelTests/Core/Command/DbDumpTest.php index fb23a39..8129410 100644 --- a/core/tests/Drupal/KernelTests/Core/Command/DbDumpTest.php +++ b/core/tests/Drupal/KernelTests/Core/Command/DbDumpTest.php @@ -71,8 +71,6 @@ public function register(ContainerBuilder $container) { $container->register('cache_factory', 'Drupal\Core\Cache\DatabaseBackendFactory') ->addArgument(new Reference('database')) ->addArgument(new Reference('cache_tags.invalidator.checksum')); - $container->register('cache.static', '\Drupal\Core\Cache\MemoryBackend') - ->addArgument('static'); } /** diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php index d505b54..f704512 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\Core\Config\Entity { use Drupal\Core\Cache\Cache; -use Drupal\Core\Cache\MemoryBackend; +use Drupal\Core\Cache\StaticCache\StaticCache; use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Language\Language; @@ -151,7 +151,7 @@ protected function setUp() { $this->entityQuery = $this->getMock('Drupal\Core\Entity\Query\QueryInterface'); $this->entityStorage = $this->getMockBuilder('Drupal\Core\Config\Entity\ConfigEntityStorage') - ->setConstructorArgs(array($this->entityType, $this->configFactory, $this->uuidService, $this->languageManager, new MemoryBackend('static'))) + ->setConstructorArgs(array($this->entityType, $this->configFactory, $this->uuidService, $this->languageManager, new StaticCache())) ->setMethods(array('getQuery')) ->getMock(); $this->entityStorage->expects($this->any()) diff --git a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php index 5a07d7f..6d942a0 100644 --- a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\Core\Entity\KeyValueStore { -use Drupal\Core\Cache\MemoryBackend; +use Drupal\Core\Cache\StaticCache\StaticCache; use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Entity\EntityInterface; @@ -121,7 +121,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, new MemoryBackend('static')); + $this->entityStorage = new KeyValueEntityStorage($this->entityType, $this->keyValueStore, $this->uuidService, $this->languageManager, new StaticCache()); $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 510a73e..30ed81e 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php @@ -8,7 +8,7 @@ namespace Drupal\Tests\Core\Entity\Sql; use Drupal\Core\Cache\CacheBackendInterface; -use Drupal\Core\Cache\MemoryBackend; +use Drupal\Core\Cache\StaticCache\StaticCache; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\Sql\SqlContentEntityStorage; @@ -343,7 +343,7 @@ public function testOnEntityTypeCreate() { ->will($this->returnValue($schema_handler)); $storage = $this->getMockBuilder('Drupal\Core\Entity\Sql\SqlContentEntityStorage') - ->setConstructorArgs(array($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager, new MemoryBackend('static'))) + ->setConstructorArgs(array($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager, new StaticCache())) ->setMethods(array('getStorageSchema')) ->getMock(); @@ -1086,7 +1086,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, new MemoryBackend('static')); + $this->entityStorage = new SqlContentEntityStorage($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager, new StaticCache()); } /** @@ -1163,7 +1163,7 @@ public function testLoadMultipleNoPersistentCache() { ->method('set'); $entity_storage = $this->getMockBuilder('Drupal\Core\Entity\Sql\SqlContentEntityStorage') - ->setConstructorArgs(array($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager, new MemoryBackend('static'))) + ->setConstructorArgs(array($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager, new StaticCache())) ->setMethods(array('getFromStorage', 'invokeStorageLoadHook')) ->getMock(); $entity_storage->method('invokeStorageLoadHook') @@ -1215,7 +1215,7 @@ public function testLoadMultiplePersistentCacheMiss() { ->with($key, $entity, CacheBackendInterface::CACHE_PERMANENT, array($this->entityTypeId . '_values', 'entity_field_info')); $entity_storage = $this->getMockBuilder('Drupal\Core\Entity\Sql\SqlContentEntityStorage') - ->setConstructorArgs(array($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager, new MemoryBackend('static'))) + ->setConstructorArgs(array($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager, new StaticCache())) ->setMethods(array('getFromStorage', 'invokeStorageLoadHook')) ->getMock(); $entity_storage->method('invokeStorageLoadHook') @@ -1272,7 +1272,7 @@ public function testHasData() { ->method('getBaseFieldDefinitions') ->will($this->returnValue($this->fieldDefinitions)); - $this->entityStorage = new SqlContentEntityStorage($this->entityType, $database, $this->entityManager, $this->cache, $this->languageManager, new MemoryBackend('static')); + $this->entityStorage = new SqlContentEntityStorage($this->entityType, $database, $this->entityManager, $this->cache, $this->languageManager, new StaticCache()); $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 1eb7e89..0a96a62 100644 --- a/core/tests/Drupal/Tests/Core/Session/UserSessionTest.php +++ b/core/tests/Drupal/Tests/Core/Session/UserSessionTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\Core\Session; -use Drupal\Core\Cache\MemoryBackend; +use Drupal\Core\Cache\StaticCache\StaticCache; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Session\UserSession; use Drupal\Tests\UnitTestCase; @@ -95,7 +95,7 @@ protected function setUp() { ))); $role_storage = $this->getMockBuilder('Drupal\user\RoleStorage') - ->setConstructorArgs(['role', new MemoryBackend('static')]) + ->setConstructorArgs(['role', new StaticCache()]) ->disableOriginalConstructor() ->setMethods(array('loadMultiple')) ->getMock();