diff --git a/app/code/community/Lesti/Fpc/Model/Fpc.php b/app/code/community/Lesti/Fpc/Model/Fpc.php index c823f2a..b0f639a 100644 --- a/app/code/community/Lesti/Fpc/Model/Fpc.php +++ b/app/code/community/Lesti/Fpc/Model/Fpc.php @@ -74,7 +74,7 @@ public function save($data, $id, $tags=array(), $lifeTime=null) if (!in_array(self::CACHE_TAG, $tags)) { $tags[] = self::CACHE_TAG; } - if ($lifeTime === null) { + if (is_null($lifeTime)) { $lifeTime = (int) $this->getFrontend()->getOption('lifetime'); } // edit cached object @@ -96,7 +96,7 @@ public function save($data, $id, $tags=array(), $lifeTime=null) if ($compressLevel != -2) { $data = gzcompress($data, $compressLevel); } - + return $this->_frontend->save( $data, $this->_id($id), @@ -113,7 +113,7 @@ public function load($id) { $data = parent::load($id); $compressLevel = Mage::getStoreConfig(self::GZCOMPRESS_LEVEL_XML_PATH); - if ($compressLevel != -2) { + if ($data !== false && $compressLevel != -2) { $data = gzuncompress($data); } diff --git a/app/code/community/Lesti/Fpc/Model/Observer/Save.php b/app/code/community/Lesti/Fpc/Model/Observer/Save.php index b8224f7..ead6ddd 100644 --- a/app/code/community/Lesti/Fpc/Model/Observer/Save.php +++ b/app/code/community/Lesti/Fpc/Model/Observer/Save.php @@ -126,8 +126,12 @@ protected function _cmsBlockSaveAfter(Mage_Cms_Model_Block $block) */ protected function _catalogProductSaveAfterMassAction(array $productIds) { - foreach ($productIds as $productId) { - $this->_getFpc()->clean(sha1('product_' . $productId)); + if (!empty($productIds)) { + $tags = array(); + foreach ($productIds as $productId) { + $tags[] = sha1('product_' . $productId); + } + $this->_getFpc()->clean($tags); } } -} \ No newline at end of file +} diff --git a/app/code/community/Lesti/Fpc/Test/Model/Fpc.php b/app/code/community/Lesti/Fpc/Test/Model/Fpc.php index 4df766c..80b3de5 100644 --- a/app/code/community/Lesti/Fpc/Test/Model/Fpc.php +++ b/app/code/community/Lesti/Fpc/Test/Model/Fpc.php @@ -14,21 +14,51 @@ /** * Class Lesti_Fpc_Test_Model_Fpc */ -class Lesti_Fpc_Test_Model_Fpc extends EcomDev_PHPUnit_Test_Case +class Lesti_Fpc_Test_Model_Fpc extends Lesti_Fpc_Test_TestCase { + /** + * @var Lesti_Fpc_Model_Fpc + */ + protected $_fpc; + + protected function setUp() + { + parent::setUp(); + $this->_fpc = Mage::getSingleton('fpc/fpc'); + } /** * @test + * @loadFixture save_load_clean.yaml */ - public function saveAndLoad() + public function saveLoadClean() { - $fpc = Mage::getSingleton('fpc/fpc'); - $key = 'lesti_fpc'; - $value = 'test'; - $fpc->save($value, $key); - $this->assertTrue($fpc->load($key) === $value); - $fpc->remove($key); - $this->assertTrue($fpc->load($key) === false); - } + $data = 'fpc_data'; + $id = 'fpc_id'; + $tag = 'tag1'; + + // check if tag tag1 (clean without array) + $this->_fpc->save($data, $id, array($tag)); + $this->assertEquals($data, $this->_fpc->load($id)); + $this->_fpc->clean($tag); + $this->assertFalse($this->_fpc->load($id)); + + // check global tag FPC (clean with array) + $this->_fpc->save($data, $id, array($tag)); + $this->assertEquals($data, $this->_fpc->load($id)); + $this->_fpc->clean(array(Lesti_Fpc_Model_Fpc::CACHE_TAG)); + $this->assertFalse($this->_fpc->load($id)); + // (global clean) + $this->_fpc->save($data, $id, array($tag)); + $this->assertEquals($data, $this->_fpc->load($id)); + $this->_fpc->clean(); + $this->assertFalse($this->_fpc->load($id)); + + // check timeout + $this->_fpc->save($data, $id, array($tag), 2); + $this->assertEquals($data, $this->_fpc->load($id)); + sleep(3); + $this->assertFalse($this->_fpc->load($id)); + } } \ No newline at end of file diff --git a/app/code/community/Lesti/Fpc/Test/Model/Fpc/fixtures/save_load_clean.yaml b/app/code/community/Lesti/Fpc/Test/Model/Fpc/fixtures/save_load_clean.yaml new file mode 100644 index 0000000..9290f12 --- /dev/null +++ b/app/code/community/Lesti/Fpc/Test/Model/Fpc/fixtures/save_load_clean.yaml @@ -0,0 +1,2 @@ +config: + default/system/fpc/gzcompress_level: 3 \ No newline at end of file