From 03e5207aa1be04eb4f7bcb033987900409a5abd8 Mon Sep 17 00:00:00 2001 From: Rachman Chavik Date: Fri, 26 Apr 2013 13:07:44 +0700 Subject: [PATCH] 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. --- lib/Cake/Cache/Engine/FileEngine.php | 1 + .../Test/Case/Cache/Engine/FileEngineTest.php | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/Cake/Cache/Engine/FileEngine.php b/lib/Cake/Cache/Engine/FileEngine.php index 2385f32d4..a04ad3d4b 100644 --- a/lib/Cake/Cache/Engine/FileEngine.php +++ b/lib/Cake/Cache/Engine/FileEngine.php @@ -369,6 +369,7 @@ class FileEngine extends CacheEngine { unlink($object->getPathName()); } } + $this->_File = null; return true; } } diff --git a/lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php b/lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php index ed61017cb..de6de80c0 100644 --- a/lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php +++ b/lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php @@ -411,6 +411,32 @@ class FileEngineTest extends CakeTestCase { $this->assertTrue(Cache::write('test_groups3', 'value3', 'file_groups')); } +/** + * 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 *