Created
February 26, 2014 11:40
-
-
Save damiankloip/9228058 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/core/lib/Drupal/Core/Cache/CacheCollector.php b/core/lib/Drupal/Core/Cache/CacheCollector.php | |
index 5971cf1..0d0e25e 100644 | |
--- a/core/lib/Drupal/Core/Cache/CacheCollector.php | |
+++ b/core/lib/Drupal/Core/Cache/CacheCollector.php | |
@@ -155,7 +155,7 @@ public function set($key, $value) { | |
$this->storage[$key] = $value; | |
// The key might have been marked for deletion. | |
unset($this->keysToRemove[$key]); | |
- $this->invalidateCache(); | |
+ $this->deleteCache(); | |
} | |
@@ -168,7 +168,7 @@ public function delete($key) { | |
$this->keysToRemove[$key] = $key; | |
// The key might have been marked for persisting. | |
unset($this->keysToPersist[$key]); | |
- $this->invalidateCache(); | |
+ $this->deleteCache(); | |
} | |
/** | |
@@ -221,20 +221,7 @@ protected function updateCache($lock = TRUE) { | |
// Lock cache writes to help avoid stampedes. | |
$lock_name = $this->cid . ':' . __CLASS__; | |
if (!$lock || $this->lock->acquire($lock_name)) { | |
- // Set and delete operations invalidate the cache item. Try to also load | |
- // an eventually invalidated cache entry, only update an invalidated cache | |
- // entry if the creation date did not change as this could result in an | |
- // inconsistent cache. | |
- if ($cache = $this->cache->get($this->cid, $this->cacheInvalidated)) { | |
- if ($this->cacheInvalidated && $cache->created != $this->cacheCreated) { | |
- // We have invalidated the cache in this request and got a different | |
- // cache entry. Do not attempt to overwrite data that might have been | |
- // changed in a different request. We'll let the cache rebuild in | |
- // later requests. | |
- $this->cache->delete($this->cid); | |
- $this->lock->release($lock_name); | |
- return; | |
- } | |
+ if ($cache = $this->cache->get($this->cid)) { | |
$data = array_merge($cache->data, $data); | |
} | |
// Remove keys marked for deletion. | |
@@ -300,10 +287,10 @@ protected function lazyLoadCache() { | |
/** | |
* Invalidate the cache. | |
*/ | |
- protected function invalidateCache() { | |
+ protected function deleteCache() { | |
// Invalidate the cache to make sure that other requests immediately see the | |
// deletion before this request is terminated. | |
- $this->cache->invalidate($this->cid); | |
+ $this->cache->delete($this->cid); | |
$this->cacheInvalidated = TRUE; | |
} | |
diff --git a/core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php b/core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php | |
index 05a987c..93c6d74 100644 | |
--- a/core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php | |
+++ b/core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php | |
@@ -102,7 +102,7 @@ public function testSetAndGetNull() { | |
$value = NULL; | |
$this->cache->expects($this->once()) | |
- ->method('invalidate') | |
+ ->method('delete') | |
->with($this->cid); | |
$this->collector->set($key, $value); | |
$this->assertTrue($this->collector->has($key)); | |
@@ -149,7 +149,7 @@ public function testDelete() { | |
$this->assertEquals($value, $this->collector->get($key)); | |
$this->cache->expects($this->once()) | |
- ->method('invalidate') | |
+ ->method('delete') | |
->with($this->cid); | |
$this->collector->delete($key); | |
$this->assertFalse($this->collector->has($key)); | |
@@ -224,53 +224,6 @@ public function testUpdateCacheLockFail() { | |
} | |
/** | |
- * Tests updating the cache when there is a conflict after cache invalidation. | |
- */ | |
- public function testUpdateCacheInvalidatedConflict() { | |
- $key = $this->randomName(); | |
- $value = $this->randomName(); | |
- | |
- $cache = (object) array( | |
- 'data' => array($key => $value), | |
- 'created' => REQUEST_TIME, | |
- ); | |
- $this->cache->expects($this->at(0)) | |
- ->method('get') | |
- ->with($this->cid) | |
- ->will($this->returnValue($cache)); | |
- | |
- $this->cache->expects($this->at(1)) | |
- ->method('invalidate') | |
- ->with($this->cid); | |
- $this->collector->set($key, 'new value'); | |
- | |
- // Set up mock objects for the expected calls, first a lock acquire, then | |
- // cache get to look for conflicting cache entries, which does find | |
- // and then it deletes the cache and aborts. | |
- $this->lock->expects($this->once()) | |
- ->method('acquire') | |
- ->with($this->cid . ':Drupal\Core\Cache\CacheCollector') | |
- ->will($this->returnValue(TRUE)); | |
- $cache = (object) array( | |
- 'data' => array($key => $value), | |
- 'created' => REQUEST_TIME + 1, | |
- ); | |
- $this->cache->expects($this->at(0)) | |
- ->method('get') | |
- ->with($this->cid) | |
- ->will($this->returnValue($cache)); | |
- $this->cache->expects($this->once()) | |
- ->method('delete') | |
- ->with($this->cid); | |
- $this->lock->expects($this->once()) | |
- ->method('release') | |
- ->with($this->cid . ':Drupal\Core\Cache\CacheCollector'); | |
- | |
- // Destruct the object to trigger the update data process. | |
- $this->collector->destruct(); | |
- } | |
- | |
- /** | |
* Tests updating the cache when a different request | |
*/ | |
public function testUpdateCacheMerge() { | |
@@ -335,7 +288,7 @@ public function testUpdateCacheDelete() { | |
// invalidation. | |
$this->cache->expects($this->at(0)) | |
->method('get') | |
- ->with($this->cid, TRUE); | |
+ ->with($this->cid); | |
$this->cache->expects($this->once()) | |
->method('set') | |
->with($this->cid, array(), Cache::PERMANENT, array()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment