diff --git a/library/Class/Catalogue.php b/library/Class/Catalogue.php index bf1696883e8ea7c0978beb0a940970ee99db9add..73def421ae702a8e9e3f7420f53c7bbcbc5e739a 100644 --- a/library/Class/Catalogue.php +++ b/library/Class/Catalogue.php @@ -441,16 +441,6 @@ class Class_Catalogue extends Storm_Model_Abstract { function() use ($preferences, $cache_vignette) { return $this->_fetchAllNoticesByPreferences($preferences, $cache_vignette); }); - - /*$cache_key = md5(serialize($preferences).$cache_vignette); - $cache = Zend_Registry::get('cache'); - - if ($this->shouldCacheContent() && $cache->test($cache_key)) - return unserialize($cache->load($cache_key)); - - $notices = $this->_fetchAllNoticesByPreferences($preferences, $cache_vignette); - $cache->save(serialize($notices), $cache_key); - return $notices;*/ } //------------------------------------------------------------------------------ diff --git a/library/Class/WebService/OAI/ResumptionToken.php b/library/Class/WebService/OAI/ResumptionToken.php index de0c8879eb2d862e2db6d5ce5778340a3c21ee26..58e04bd94c2ff76ff6a1e9325a3dd5b99787fd2a 100644 --- a/library/Class/WebService/OAI/ResumptionToken.php +++ b/library/Class/WebService/OAI/ResumptionToken.php @@ -21,21 +21,21 @@ class Class_WebService_OAI_ResumptionToken { - protected static $_cache = null; + protected $_cache = null; protected $_params; protected $_list_size; protected $_cursor = 0; protected $_page_number = 1; - public static function defaultCache($cache) { - self::$_cache = $cache; - } + public function __sleep(){ + return ['_params', '_list_size', '_cursor', '_page_number']; + } - public static function getCache() { - if (!isset(self::$_cache)) - return Zend_Registry::get('cache'); - return self::$_cache; + public function getCache() { + if (!isset($this->_cache)) + $this->_cache = (new Storm_Cache()); + return $this->_cache; } @@ -45,7 +45,8 @@ class Class_WebService_OAI_ResumptionToken { public static function find($key) { - return unserialize(self::getCache()->load($key)); + xdebug_break(); + return (new Storm_Cache())->load($key); } @@ -57,8 +58,7 @@ class Class_WebService_OAI_ResumptionToken { } public function save() { - $data = serialize($this); - return $this->getCache()->save($data, md5($data)); + return $this->getCache()->save($this,md5(serialize($this))); } diff --git a/tests/application/modules/opac/controllers/OAIControllerListIdentifiersTest.php b/tests/application/modules/opac/controllers/OAIControllerListIdentifiersTest.php index 45ce43ba4ce165d76a6d1edbaace41c81724bb36..41fb33acb408de846824dfde4a45df4255adc81a 100644 --- a/tests/application/modules/opac/controllers/OAIControllerListIdentifiersTest.php +++ b/tests/application/modules/opac/controllers/OAIControllerListIdentifiersTest.php @@ -201,7 +201,8 @@ class OAIControllerListIdentifiersWithPaginatorTest extends AbstractControllerTe $this->_cache = Storm_Test_ObjectWrapper::mock() ->whenCalled('save') ->answers(true); - Class_WebService_OAI_ResumptionToken::defaultCache($this->_cache); + //Class_WebService_OAI_ResumptionToken::defaultCache($this->_cache); + Storm_Cache::setDefaultZendCache($this->_cache); $this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&set=zork'); $this->_xml = $this->_response->getBody(); @@ -209,7 +210,8 @@ class OAIControllerListIdentifiersWithPaginatorTest extends AbstractControllerTe public function tearDown() { - Class_WebService_OAI_ResumptionToken::defaultCache(null); + //Class_WebService_OAI_ResumptionToken::defaultCache(null); + Storm_Cache::setDefaultZendCache(null); parent::tearDown(); } @@ -239,7 +241,8 @@ class OAIControllerListIdentifiersInvalidParamsTest extends AbstractControllerTe public function tearDown() { - Class_WebService_OAI_ResumptionToken::defaultCache(null); + //Class_WebService_OAI_ResumptionToken::defaultCache(null); + Storm_Cache::setDefaultZendCache(null); parent::tearDown(); } @@ -293,8 +296,9 @@ class OAIControllerListIdentifiersInvalidParamsTest extends AbstractControllerTe $cache = Storm_Test_ObjectWrapper::mock() ->whenCalled('load') ->answers(false); - Class_WebService_OAI_ResumptionToken::defaultCache($cache); - $this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&set=zork&resumptionToken=Zork'); + //Class_WebService_OAI_ResumptionToken::defaultCache($cache); + Storm_Cache::setDefaultZendCache($cache); + $this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&set=zork&resumptionToken=Zork',true); $this->_xpath->assertXPath($this->_response->getBody(), '//oai:error[@code="badResumptionToken"]'); } diff --git a/tests/application/modules/opac/controllers/OAIControllerListRecordsTest.php b/tests/application/modules/opac/controllers/OAIControllerListRecordsTest.php index c2b25291a028d94ebb33a7a749faa0a8691f440b..53a4d91d164745ccdb25ae594c01b5e18c04d893 100644 --- a/tests/application/modules/opac/controllers/OAIControllerListRecordsTest.php +++ b/tests/application/modules/opac/controllers/OAIControllerListRecordsTest.php @@ -118,7 +118,7 @@ class OAIControllerListRecordsInZorkSetWithBadResumptionTokenTest extends OAICon $cache = Storm_Test_ObjectWrapper::mock() ->whenCalled('load') ->answers(false); - Class_WebService_OAI_ResumptionToken::defaultCache($cache); + Storm_Cache::setDefaultZendCache($cache); Class_Catalogue::whenCalled('countNoticesFor')->answers(0); diff --git a/tests/library/Class/WebService/OAI/ResumptionTokenTest.php b/tests/library/Class/WebService/OAI/ResumptionTokenTest.php index fdd7d853446a88d624c71544d14f6e0b6b50f5aa..06bea9629ddae39ef8b276ef04a6e9a97e78906c 100644 --- a/tests/library/Class/WebService/OAI/ResumptionTokenTest.php +++ b/tests/library/Class/WebService/OAI/ResumptionTokenTest.php @@ -33,20 +33,23 @@ class ResumptionTokenTest extends PHPUnit_Framework_TestCase { 'metadataPrefix' => 'oai_dc', 'set' => 'bande_dessinees'); $this->_cache = Storm_Test_ObjectWrapper::mock(); - Class_WebService_OAI_ResumptionToken::defaultCache($this->_cache); + Storm_Cache::setDefaultZendCache($this->_cache); $this->_token = Class_WebService_OAI_ResumptionToken::newWithParamsAndListSize($this->_request_params, 10000); $this->_cache ->whenCalled('save') ->answers(true) ->whenCalled('load') - ->answers(false) + ->answers(false); + $this->_token->save(); + + $this->_cache ->whenCalled('load') ->with(md5(serialize($this->_token))) ->answers(serialize($this->_token)); - $this->_token->save(); + $this->_xpath = new Storm_Test_XPathXML(); $this->_builder = new Class_Xml_Builder(); @@ -55,7 +58,7 @@ class ResumptionTokenTest extends PHPUnit_Framework_TestCase { /** @test */ public function saveShouldSerializeTokenIntoCache() { - $this->assertEquals($this->_token, + $this->assertEquals(Class_WebService_OAI_ResumptionToken::newWithParamsAndListSize($this->_request_params, 10000, 0, 1), unserialize($this->_cache->getFirstAttributeForLastCallOn('save'))); } @@ -76,7 +79,8 @@ class ResumptionTokenTest extends PHPUnit_Framework_TestCase { /** @test */ public function findByMd5ShouldAnswerToken() { - $this->assertEquals($this->_token, Class_WebService_OAI_ResumptionToken::find(md5(serialize($this->_token)))); + xdebug_break(); + $this->assertEquals(Class_WebService_OAI_ResumptionToken::newWithParamsAndListSize($this->_request_params, 10000, 0, 1), Class_WebService_OAI_ResumptionToken::find(md5(serialize($this->_token)))); } @@ -86,13 +90,6 @@ class ResumptionTokenTest extends PHPUnit_Framework_TestCase { } - /** @test */ - public function defaultCacheShouldBeZendRegistryCache() { - Class_WebService_OAI_ResumptionToken::defaultCache(null); - $this->assertEquals(Zend_Registry::get('cache'), $this->_token->getCache()); - } - - /** @test */ public function renderShouldAnswerXml() { $this->_xpath->assertXPathContentContains($this->_token->renderOn($this->_builder),