diff --git a/core/core.services.yml b/core/core.services.yml index 6310c21..274041b 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -1639,3 +1639,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/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/StaticCache/LruStaticCache.php b/core/lib/Drupal/Core/Cache/StaticCache/LruStaticCache.php new file mode 100644 index 0000000..e4c7693 --- /dev/null +++ b/core/lib/Drupal/Core/Cache/StaticCache/LruStaticCache.php @@ -0,0 +1,174 @@ +allowedSlots = $slots; + } + $this->availableSlots = $this->allowedSlots; + } + + /** + * {@inheritdoc} + */ + public function get($cid, $allow_invalid = FALSE) { + if ($cached = parent::get($cid, $allow_invalid)) { + // Check if the item is already at the end of the positions array. If it + // is, it can't be moved any further up. Otherwise move it there. + if (end($this->positions) !== $cid) { + $current_position = array_search($cid, $this->positions); + unset($this->positions[$current_position]); + $this->positions[] = $cid; + } + } + return $cached; + } + + /** + * {@inheritdoc} + */ + public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array()) { + // If there are no available slots, and none of the slots are already used + // by this cache ID, remove the least recently used item. + $current_position = array_search($cid, $this->positions); + if (!$this->availableSlots && $current_position === FALSE) { + $key = array_shift($this->positions); + unset($this->cache[$key]); + $this->availableSlots++; + } + // Setting an already-set item moves it to the most recently used spot but + // does not take up any extra slots. + if ($current_position !== FALSE) { + unset($this->positions[$current_position]); + } + else { + $this->availableSlots--; + } + $this->positions[] = $cid; + return parent::set($cid, $data, $expire, $tags); + } + + /** + * {@inheritdoc} + */ + public function delete($cid) { + $current_position = array_search($cid, $this->positions); + if ($current_position !== FALSE) { + $this->availableSlots++; + unset($this->positions[$current_position]); + } + parent::delete($cid); + } + + /** + * {@inheritdoc} + */ + public function deleteMultiple(array $cids) { + foreach ($cids as $cid) { + $this->delete($cid); + } + } + + /** + * {@inheritdoc} + */ + public function invalidate($cid) { + parent::invalidate($cid); + // Move the item to the least recently used position if it's not already + // there. + if (isset($this->cache[$cid])) { + if (reset($this->positions) !== $cid) { + $current_position = array_search($cid, $this->positions); + unset($this->positions[$current_position]); + array_unshift($this->positions, $cid); + } + } + } + + /** + * {@inheritdoc} + */ + public function invalidateMultiple(array $cids) { + foreach ($cids as $cid) { + $this->invalidate($cid); + } + } + + /** + * {@inheritdoc} + */ + public function invalidateTags(array $tags) { + foreach ($this->cache as $cid => $item) { + if (array_intersect($tags, $item->tags)) { + $this->invalidate($cid); + } + } + } + + /** + * {@inheritdoc} + */ + public function deleteAll() { + $this->resetSlots(); + return parent::deleteAll(); + } + + /** + * {@inheritdoc} + */ + public function reset() { + $this->resetSlots(); + return parent::reset(); + } + + /** + * Reset the available slots and positions. + */ + protected function resetSlots() { + $this->availableSlots = $this->allowedSlots; + $this->positions = []; + } + +} diff --git a/core/lib/Drupal/Core/Cache/StaticCache/StaticCache.php b/core/lib/Drupal/Core/Cache/StaticCache/StaticCache.php new file mode 100644 index 0000000..b252807 --- /dev/null +++ b/core/lib/Drupal/Core/Cache/StaticCache/StaticCache.php @@ -0,0 +1,65 @@ +data)) { + return FALSE; + } + // Check expire time. + $cache->valid = $cache->expire == Cache::PERMANENT || $cache->expire >= $this->getRequestTime(); + + if (!$allow_invalid && !$cache->valid) { + return FALSE; + } + + return $cache; + } + + /** + * {@inheritdoc} + */ + public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array()) { + assert('\Drupal\Component\Assertion\Inspector::assertAllStrings($tags)', 'Cache Tags must be strings.'); + $tags = array_unique($tags); + // Sort the cache tags so that they are stored consistently in the database. + sort($tags); + $this->cache[$cid] = (object) array( + 'cid' => $cid, + 'data' => $data, + 'created' => $this->getRequestTime(), + 'expire' => $expire, + 'tags' => $tags, + ); + } + +} diff --git a/core/lib/Drupal/Core/Cache/StaticCache/StaticCacheInterface.php b/core/lib/Drupal/Core/Cache/StaticCache/StaticCacheInterface.php new file mode 100644 index 0000000..8c98194 --- /dev/null +++ b/core/lib/Drupal/Core/Cache/StaticCache/StaticCacheInterface.php @@ -0,0 +1,19 @@ +configFactory = $config_factory; $this->uuidService = $uuid_service; @@ -317,43 +321,10 @@ protected function has($id, EntityInterface $entity) { } /** - * 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 = array(); - // 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 getCacheId($id) { + return parent::getCacheId($id) . ':' . $config_overrides_key = $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 afdce40..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; @@ -43,9 +44,12 @@ * The entity manager. * @param \Drupal\Core\Cache\CacheBackendInterface $cache * The cache backend to be used. + * @param \Drupal\Core\Cache\CacheBackendInterface $static_cache + * The cache backend to be used. */ - 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, 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; $this->cacheBackend = $cache; @@ -58,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') ); } @@ -629,17 +634,17 @@ protected function setPersistentCache($entities) { */ public function resetCache(array $ids = NULL) { if ($ids) { - $cids = array(); - foreach ($ids as $id) { - unset($this->entities[$id]); - $cids[] = $this->buildCacheId($id); - } + parent::resetCache($ids); if ($this->entityType->isPersistentlyCacheable()) { + $cids = array(); + foreach ($ids as $id) { + $cids[] = $this->buildCacheId($id); + } $this->cacheBackend->deleteMultiple($cids); } } else { - $this->entities = array(); + parent::resetCache(); if ($this->entityType->isPersistentlyCacheable()) { Cache::invalidateTags(array($this->entityTypeId . '_values')); } diff --git a/core/lib/Drupal/Core/Entity/EntityStorageBase.php b/core/lib/Drupal/Core/Entity/EntityStorageBase.php index f583121..5251745 100644 --- a/core/lib/Drupal/Core/Entity/EntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/EntityStorageBase.php @@ -3,6 +3,7 @@ namespace Drupal\Core\Entity; use Drupal\Core\Entity\Query\QueryInterface; +use Drupal\Core\Cache\StaticCache\StaticCacheInterface; /** * A base entity storage class. @@ -73,18 +74,28 @@ protected $entityClass; /** + * The static cache. + * + * @var \Drupal\Core\StaticCache\StaticCacheInterface + */ + protected $staticCache; + + /** * Constructs an EntityStorageBase instance. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type definition. + * @param \Drupal\Core\Cache\StaticCache\StaticCacheInterface + * The static cache. */ - public function __construct(EntityTypeInterface $entity_type) { + 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->staticCache = isset($static_cache) ? $static_cache : \Drupal::service('static_cache'); } /** @@ -102,6 +113,13 @@ public function getEntityType() { } /** + * Build a cache ID for an entity. + */ + protected function getCacheId($id) { + return 'entity_storage_cache:' . $this->entityTypeId . ':' . $id; + } + + /** * {@inheritdoc} */ public function loadUnchanged($id) { @@ -115,11 +133,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->staticCache->delete($this->getCacheId($id)); } } else { - $this->entities = array(); + // Call the backend method directly. + $this->staticCache->invalidateTags(['entity_static_cache']); } } @@ -135,8 +154,12 @@ public function resetCache(array $ids = NULL) { protected function getFromStaticCache(array $ids) { $entities = array(); // 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->staticCache->get($this->getCacheId($id))) { + $entities[$id] = $cached->data; + } + } } return $entities; } @@ -149,7 +172,9 @@ protected function getFromStaticCache(array $ids) { */ protected function setStaticCache(array $entities) { if ($this->entityType->isStaticallyCacheable()) { - $this->entities += $entities; + foreach ($entities as $id => $entity) { + $this->staticCache->set($this->getCacheId($entity->id()), $entity, StaticCacheInterface::CACHE_PERMANENT, ['entity_static_cache']); + } } } @@ -529,5 +554,4 @@ public function getAggregateQuery($conjunction = 'AND') { * The name of the service for the query for this entity storage. */ abstract protected function getQueryServiceName(); - } diff --git a/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php b/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php index 478bca7..395414d 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\StaticCache\StaticCacheInterface; use Drupal\Core\Config\Entity\Exception\ConfigEntityIdLengthException; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\EntityInterface; @@ -50,6 +51,13 @@ class KeyValueEntityStorage extends EntityStorageBase { protected $languageManager; /** + * The static cache. + * + * @var \Drupal\Core\StaticCache\StaticCacheInterface + */ + protected $staticCache; + + /** * Constructs a new KeyValueEntityStorage. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type @@ -60,9 +68,12 @@ class KeyValueEntityStorage extends EntityStorageBase { * The UUID service. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. + * @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) { - parent::__construct($entity_type); + 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 e115bd2..f35ed95 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php @@ -126,7 +126,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('static_cache') ); } @@ -154,9 +155,12 @@ public function getFieldStorageDefinitions() { * The cache backend to be used. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. + * @param \Drupal\Core\Cache\CacheBackendInterface $static_cache + * The static 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, CacheBackendInterface $static_cache = NULL) { + $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; $this->initTableLayout(); diff --git a/core/modules/field/src/Tests/EntityReference/EntityReferenceIntegrationTest.php b/core/modules/field/src/Tests/EntityReference/EntityReferenceIntegrationTest.php index 4c099fe..8571488 100644 --- a/core/modules/field/src/Tests/EntityReference/EntityReferenceIntegrationTest.php +++ b/core/modules/field/src/Tests/EntityReference/EntityReferenceIntegrationTest.php @@ -82,9 +82,7 @@ public function testSupportedEntityTypesAndWidgets() { // Try to post the form again with no modification and check if the field // values remain the same. - /** @var \Drupal\Core\Entity\EntityStorageInterface $storage */ - $storage = $this->container->get('entity_type.manager')->getStorage($this->entityType); - $entity = current($storage->loadByProperties(['name' => $entity_name])); + $entity = current(\Drupal::entityTypeManager()->getStorage($this->entityType)->loadByProperties(['name' => $entity_name])); $this->drupalGet($this->entityType . '/manage/' . $entity->id() . '/edit'); $this->assertFieldByName($this->fieldName . '[0][target_id]', $referenced_entities[0]->label() . ' (' . $referenced_entities[0]->id() . ')'); $this->assertFieldByName($this->fieldName . '[1][target_id]', $referenced_entities[1]->label() . ' (' . $referenced_entities[1]->id() . ')'); @@ -110,7 +108,7 @@ public function testSupportedEntityTypesAndWidgets() { // Try to post the form again with no modification and check if the field // values remain the same. - $entity = current($storage->loadByProperties(['name' => $entity_name])); + $entity = current(\Drupal::entityTypeManager()->getStorage($this->entityType)->loadByProperties(['name' => $entity_name])); $this->drupalGet($this->entityType . '/manage/' . $entity->id() . '/edit'); $this->assertFieldByName($this->fieldName . '[target_id]', $target_id . ' (' . $referenced_entities[1]->id() . ')'); @@ -121,7 +119,7 @@ public function testSupportedEntityTypesAndWidgets() { // Since we don't know the form structure for these widgets, just test // that editing and saving an already created entity works. $exclude = array('entity_reference_autocomplete', 'entity_reference_autocomplete_tags'); - $entity = current($storage->loadByProperties(['name' => $entity_name])); + $entity = current(\Drupal::entityTypeManager()->getStorage($this->entityType)->loadByProperties(['name' => $entity_name])); $supported_widgets = \Drupal::service('plugin.manager.field.widget')->getOptions('entity_reference'); $supported_widget_types = array_diff(array_keys($supported_widgets), $exclude); @@ -175,8 +173,7 @@ public function testSupportedEntityTypesAndWidgets() { * An array of referenced entities. */ protected function assertFieldValues($entity_name, $referenced_entities) { - $entity = current($this->container->get('entity_type.manager')->getStorage( - $this->entityType)->loadByProperties(['name' => $entity_name])); + $entity = current(\Drupal::entityTypeManager()->getStorage($this->entityType)->loadByProperties(['name' => $entity_name])); $this->assertTrue($entity, format_string('%entity_type: Entity found in the database.', array('%entity_type' => $this->entityType))); diff --git a/core/tests/Drupal/Tests/Core/Cache/LruStaticCacheTest.php b/core/tests/Drupal/Tests/Core/Cache/LruStaticCacheTest.php new file mode 100644 index 0000000..d4e93d0 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Cache/LruStaticCacheTest.php @@ -0,0 +1,115 @@ +staticCache = new LruStaticCache(3); + $cids = [ + ['sparrow', 'sparrow'], + ['pidgie', 'pidgie'], + ['crow', 'crow'], + ]; + foreach ($cids as $items) { + $this->staticCache->set($items[0], $items[0]); + } + $this->assertCids($cids); + $this->staticCache->set('cuckoo', 'cuckoo'); + $cids[0] = ['sparrow', FALSE]; + $cids[]= ['cuckoo', 'cuckoo']; + $this->assertCids($cids); + + // Now bring pidgie to the most recently used spot. + $this->staticCache->get('pidgie'); + + $this->staticCache->set('bigger_cuckoo', 'bigger_cuckoo'); + $cids[2] = ['crow', FALSE]; + $cids[5] = ['bigger_cuckoo', 'bigger_cuckoo']; + $this->assertCids($cids); + + // Confirm that setting the same item multiple times only uses one slot. + $this->staticCache->set('bigger_cuckoo', 'bigger_cuckoo'); + $this->staticCache->set('bigger_cuckoo', 'bigger_cuckoo'); + $this->staticCache->set('bigger_cuckoo', 'bigger_cuckoo'); + $this->staticCache->set('bigger_cuckoo', 'bigger_cuckoo'); + $this->staticCache->set('bigger_cuckoo', 'bigger_cuckoo'); + $this->assertCids($cids); + + // Confirm that deleting the same item multiple times only frees up one + // slot. + $this->staticCache->delete('bigger_cuckoo', 'bigger_cuckoo'); + $this->staticCache->delete('bigger_cuckoo', 'bigger_cuckoo'); + $this->staticCache->delete('bigger_cuckoo', 'bigger_cuckoo'); + $this->staticCache->delete('bigger_cuckoo', 'bigger_cuckoo'); + $this->staticCache->delete('bigger_cuckoo', 'bigger_cuckoo'); + $this->staticCache->delete('bigger_cuckoo', 'bigger_cuckoo'); + $this->staticCache->set('bigger_cuckoo', 'bigger_cuckoo'); + $this->assertCids($cids); + $this->staticCache->set('crow', 'crow'); + $cids[2] = ['crow', 'crow']; + $cids[1] = ['pidgie', FALSE]; + $this->assertCids($cids); + } + + public function testInvalidate() { + $this->staticCache = new LruStaticCache(3); + $cids = [ + ['sparrow', 'sparrow'], + ['pidgie', 'pidgie'], + ['crow', 'crow'], + ]; + foreach ($cids as $items) { + $this->staticCache->set($items[0], $items[0]); + } + $this->assertCids($cids); + $this->staticCache->invalidate('crow'); + $this->staticCache->set('cuckoo', 'cuckoo', LruStaticCache::CACHE_PERMANENT, ['cuckoo']); + $cids[2] = ['crow', FALSE]; + $cids[]= ['cuckoo', 'cuckoo']; + $this->assertCids($cids); + $this->staticCache->invalidateTags(['cuckoo']); + $this->staticCache->set('crow', 'crow'); + $cids[2] = ['crow', 'crow']; + $cids[3] = ['cuckoo', FALSE]; + $this->assertCids($cids); + + $this->staticCache->invalidateMultiple(['pidgie', 'crow']); + $this->staticCache->set('duck', 'duck'); + $cids[1] = ['pidgie', FALSE]; + $this->staticCache->set('chicken', 'chicken'); + $cids[2] = ['crow', FALSE]; + $this->assertCids($cids); + } + + protected function assertCids($cids) { + foreach ($cids as $items) { + $cached = $this->staticCache->get($items[0]); + if ($items[1]) { + $this->assertEquals($items[1], $cached->data); + } + else { + $this->assertFalse($cached); + } + } + } + + +} diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php index 2c4a01b..f704512 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\Core\Config\Entity { use Drupal\Core\Cache\Cache; +use Drupal\Core\Cache\StaticCache\StaticCache; use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Language\Language; @@ -150,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)) + ->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 3c337bb..6d942a0 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\StaticCache\StaticCache; use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Entity\EntityInterface; @@ -120,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); + $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 02970d7..30ed81e 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\StaticCache\StaticCache; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\Sql\SqlContentEntityStorage; @@ -342,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)) + ->setConstructorArgs(array($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager, new StaticCache())) ->setMethods(array('getStorageSchema')) ->getMock(); @@ -1085,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); + $this->entityStorage = new SqlContentEntityStorage($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager, new StaticCache()); } /** @@ -1162,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)) + ->setConstructorArgs(array($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager, new StaticCache())) ->setMethods(array('getFromStorage', 'invokeStorageLoadHook')) ->getMock(); $entity_storage->method('invokeStorageLoadHook') @@ -1214,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)) + ->setConstructorArgs(array($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager, new StaticCache())) ->setMethods(array('getFromStorage', 'invokeStorageLoadHook')) ->getMock(); $entity_storage->method('invokeStorageLoadHook') @@ -1271,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); + $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 f83515c..0a96a62 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\StaticCache\StaticCache; 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 StaticCache()]) ->disableOriginalConstructor() ->setMethods(array('loadMultiple')) ->getMock();