public function postRequest(\SS_HTTPRequest $request, \SS_HTTPResponse $response, \DataModel $model) { if ($request->getVar('clear') && Member::currentUserID() && Permission::check('ADMIN')) { $key = trim($request->getVar('url'), '/'); $key = (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '') . '/' . $key; $item = $this->dynamicCache->get($key); if ($item) { $response->addHeader('X-SilverStripe-Cache', 'deleted ' . $key); $this->dynamicCache->delete($key); } } }
public function urlIsCached($host, $url, $checkingRemap = false) { if (!$this->enabled) { return false; } $url = $this->urlForCaching($url); $key = "{$host}/{$url}"; if ($this->staticCache) { $this->currentItem = $this->staticCache->get($key); if ($this->currentItem && strlen($this->currentItem->Content) && $this->includeCacheHeaders) { $this->headers[] = 'X-SilverStripe-Cache: hit at ' . date('r'); } } if (!$this->currentItem && $this->dynamicCache && $this->canCache($host, $url)) { $this->currentItem = $this->dynamicCache->get($key); if ($this->currentItem && strlen($this->currentItem->Content) && $this->includeCacheHeaders) { $this->headers[] = 'X-SilverStripe-Cache: gen-hit at ' . date('r'); } } if ($this->currentItem && !strlen($this->currentItem->Content)) { $this->currentItem = null; } if (!$this->currentItem && !$checkingRemap) { $remapped = $this->remappedHost($host); if ($remapped) { return $this->urlIsCached($remapped, $url, true); } } return is_object($this->currentItem) && strlen($this->currentItem->Content); }
public function testTagElement() { Filesystem::removeFolder(TEMP_FOLDER . '/my_test_cache'); $cache = new SimpleCache(new SimpleFileBasedCacheStore(TEMP_FOLDER . '/my_test_cache')); $object = new stdClass(); $object->Title = "Object Title"; $cache->store('one', $object, -1, array('mytag')); $other = new stdClass(); $other->Title = 'Second object'; $cache->store('two', $other, -1, array('mytag')); $elems = $cache->getByTag('mytag'); $this->assertEquals(2, count($elems)); $this->assertEquals('Second object', $elems[1]->Title); $cache->deleteByTag('mytag'); $one = $cache->get('one'); $this->assertNull($one); }
public function urlIsCached($host, $url) { if (!$this->enabled) { return false; } $key = "{$host}/{$url}"; if ($this->staticCache) { $this->currentItem = $this->staticCache->get($key); if ($this->currentItem) { $this->headers[] = 'X-SilverStripe-Cache: hit at ' . @date('r'); } } if (!$this->currentItem && $this->dynamicCache && $this->canCache($host, $url)) { $this->currentItem = $this->dynamicCache->get($key); if ($this->currentItem) { $this->headers[] = 'X-SilverStripe-Cache: gen-hit at ' . @date('r'); } } return !is_null($this->currentItem); }