diff -u b/core/lib/Drupal/Core/Cache/ArrayBackend.php b/core/lib/Drupal/Core/Cache/ArrayBackend.php --- b/core/lib/Drupal/Core/Cache/ArrayBackend.php +++ b/core/lib/Drupal/Core/Cache/ArrayBackend.php @@ -99,9 +99,7 @@ $this->cache[$cid] = (object) array( 'cid' => $cid, 'data' => $data, - // $expire is ignored because in the context of a static cache that - // persists for a single request it has no meaning. - 'expire' => CACHE_PERMANENT, + 'expire' => $expire, 'tags' => $tags, 'checksum' => $this->checksum($this->flattenTags($tags)), ); @@ -159,7 +157,8 @@ * Implements Drupal\Core\Cache\CacheBackendInterface::expire(). * * Cache expiration is not implemented for PHP ArrayBackend as this backend - * only persists during a single request. + * only persists during a single request and expiration are done using + * REQUEST_TIME. */ public function expire() { } diff -u b/core/modules/system/lib/Drupal/system/Tests/Cache/GenericBackendUnitTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Cache/GenericBackendUnitTestBase.php --- b/core/modules/system/lib/Drupal/system/Tests/Cache/GenericBackendUnitTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/Cache/GenericBackendUnitTestBase.php @@ -133,20 +133,18 @@ public function testSetGet() { $backend = $this->getCacheBackend(); - $cid = 'test1'; $data = 7; - $this->assertIdentical(FALSE, $backend->get($cid), format_string("Backend does not contain data for cache id %cid.", array('%cid' => $cid))); - $backend->set($cid, $data); - $cached = $backend->get($cid); - $this->assert(is_object($cached), format_string("Backend returned an object for cache id %cid.", array('%cid' => $cid))); + $this->assertIdentical(FALSE, $backend->get('test1'), "Backend does not contain data for cache id test1."); + $backend->set('test1', $data); + $cached = $backend->get('test1'); + $this->assert(is_object($cached), "Backend returned an object for cache id test1."); $this->assertIdentical($data, $cached->data); - $cid = 'test2'; $data = array('value' => 3); - $this->assertIdentical(FALSE, $backend->get($cid), format_string("Backend does not contain data for cache id %cid.", array('%cid' => $cid))); - $backend->set($cid, $data); - $cached = $backend->get($cid); - $this->assert(is_object($cached), format_string("Backend returned an object for cache id %cid.", array('%cid' => $cid))); + $this->assertIdentical(FALSE, $backend->get('test2'), "Backend does not contain data for cache id test2."); + $backend->set('test2', $data); + $cached = $backend->get('test2'); + $this->assert(is_object($cached), "Backend returned an object for cache id test2."); $this->assertIdentical($data, $cached->data); } @@ -156,27 +154,22 @@ public function testDelete() { $backend = $this->getCacheBackend(); - $cid = 'test1'; - $this->assertIdentical(FALSE, $backend->get($cid), format_string("Backend does not contain data for cache id %cid.", array('%cid' => $cid))); - $backend->set($cid, 7); - $this->assert(is_object($backend->get($cid)), format_string("Backend returned an object for cache id %cid.", array('%cid' => $cid))); - - $cid = 'test2'; - $this->assertIdentical(FALSE, $backend->get($cid), format_string("Backend does not contain data for cache id %cid.", array('%cid' => $cid))); - $backend->set($cid, 3); - $this->assert(is_object($backend->get($cid)), format_string("Backend returned an object for cache id %cid.", array('%cid' => $cid))); - - $cid = 'test1'; - $backend->delete($cid); - $this->assertIdentical(FALSE, $backend->get($cid), format_string("Backend does not contain data for cache id %cid after deletion.", array('%cid' => $cid))); - - $cid = 'test2'; - $cached = $backend->get($cid); - $this->assert(is_object($backend->get($cid)), format_string("Backend still has an object for cache id %cid.", array('%cid' => $cid))); - - $cid = 'test2'; - $backend->delete($cid); - $this->assertIdentical(FALSE, $backend->get($cid), format_string("Backend does not contain data for cache id %cid after deletion.", array('%cid' => $cid))); + $this->assertIdentical(FALSE, $backend->get('test1'), "Backend does not contain data for cache id test1."); + $backend->set('test1', 7); + $this->assert(is_object($backend->get('test1')), "Backend returned an object for cache id test1."); + + $this->assertIdentical(FALSE, $backend->get('test2'), "Backend does not contain data for cache id test2."); + $backend->set('test2', 3); + $this->assert(is_object($backend->get('test2')), "Backend returned an object for cache id %cid."); + + $backend->delete('test1'); + $this->assertIdentical(FALSE, $backend->get('test1'), "Backend does not contain data for cache id test1 after deletion."); + + $cached = $backend->get('test2'); + $this->assert(is_object($backend->get('test2')), "Backend still has an object for cache id test2."); + + $backend->delete('test2'); + $this->assertIdentical(FALSE, $backend->get('test2'), "Backend does not contain data for cache id test2 after deletion."); } /** @@ -263,10 +256,10 @@ } // Test return array values. - $this->assertIdentical($ret['test2']->data, 3, "Existing key 2 has the correct value."); - $this->assertIdentical($ret['test3']->data, 5, "Existing key 3 has the correct value."); - $this->assertIdentical($ret['test6']->data, 13, "Existing key 6 has the correct value."); - $this->assertIdentical($ret['test7']->data, 17, "Existing key 7 has the correct value."); + $this->assertIdentical($ret['test2']->data, 3, "Existing cache id test2 has the correct value."); + $this->assertIdentical($ret['test3']->data, 5, "Existing cache id test3 has the correct value."); + $this->assertIdentical($ret['test6']->data, 13, "Existing cache id test6 has the correct value."); + $this->assertIdentical($ret['test7']->data, 17, "Existing cache id test7 has the correct value."); // Proceed the test a second time after deleting and setting new keys which // ensures no static cache stall.