Browse Source

Fix: write() after clearGroup() does not actually write to file

Although clearGroup() does not use $this->_File, it needs to be null-ed
so that subsequent write() call do not see stale object.
Rachman Chavik 13 years ago
parent
commit
03e5207aa1

+ 1 - 0
lib/Cake/Cache/Engine/FileEngine.php

@@ -369,6 +369,7 @@ class FileEngine extends CacheEngine {
 				unlink($object->getPathName());
 			}
 		}
+		$this->_File = null;
 		return true;
 	}
 }

+ 26 - 0
lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php

@@ -412,6 +412,32 @@ class FileEngineTest extends CakeTestCase {
 	}
 
 /**
+ * Test that clearing with repeat writes works properly
+ */
+	public function testClearingWithRepeatWrites() {
+		Cache::config('repeat', array(
+			'engine' => 'File', 'groups' => array('users')
+		));
+
+		$this->assertTrue(Cache::write('user', 'rchavik', 'repeat'));
+		$this->assertEquals('rchavik', Cache::read('user', 'repeat'));
+
+		Cache::delete('user', 'repeat');
+		$this->assertEquals(false, Cache::read('user', 'repeat'));
+
+		$this->assertTrue(Cache::write('user', 'ADmad', 'repeat'));
+		$this->assertEquals('ADmad', Cache::read('user', 'repeat'));
+
+		Cache::clearGroup('users', 'repeat');
+		$this->assertEquals(false, Cache::read('user', 'repeat'));
+
+		$this->assertTrue(Cache::write('user', 'markstory', 'repeat'));
+		$this->assertEquals('markstory', Cache::read('user', 'repeat'));
+
+		Cache::drop('repeat');
+	}
+
+/**
  * Tests that deleting from a groups-enabled config is possible
  *
  * @return void