/** * */ public function testRemoveCachedPage() { $model = $this->objFromFixture('SiteTree', 'servicetest-page-1'); $service = new CacheableNavigationService('Live', null, $model); // Entire cache should be empty $this->assertNull($service->_cached); // Populate the cache and re-test $this->assertTrue($service->refreshCachedPage()); $this->assertNotNull($service->_cached); $this->assertInstanceOf('CachedNavigation', $service->_cached); $cachedObject = $service->_cached->get_site_map(); // $cachedObject not zero-indexed as array keys are taken for SS-generated ID's from each fixture $this->assertCount(1, $cachedObject); $this->assertInstanceOf('CacheableSiteTree', $cachedObject[1]); // So far so good, now remove it: $this->assertTrue($service->removeCachedPage()); // Cache should be devoid of SiteTree-esque objects $this->assertContainsOnlyInstancesOf('CacheableSiteConfig', $service->_cached); }
/** * * @param array $modes * @param boolean $forceRemoval Whether to unset() children in {@link CacheableSiteTree::removeChild()}. * @return void */ public function removePageCache($modes, $forceRemoval = true) { // Increase memory to max-allowable CacheableConfig::configure_memory_limit(); $siteConfig = $this->owner->getSiteConfig(); if (!$siteConfig->exists()) { $siteConfig = SiteConfig::current_site_config(); } foreach ($modes as $stage => $mode) { $service = new CacheableNavigationService($mode, $siteConfig, $this->owner); $cache_frontend = $service->getCacheableFrontEnd(); $id = $service->getIdentifier(); $cached = $cache_frontend->load($id); if ($cached) { $cached_site_config = $cached->get_site_config(); if (!$cached_site_config) { $service->refreshCachedConfig(); } $service->removeCachedPage($forceRemoval); } } }