public function testFlush() { $cache = new CM_Cache_Storage_File(); $cache->set('foo', 'bar'); $this->assertSame('bar', $cache->get('foo')); $cache->flush(); $this->assertFalse($cache->get('foo')); }
/** * @param string $content * @return string */ protected function _minify($content) { $md5 = md5($content); $cacheKey = CM_CacheConst::App_Resource . '_md5:' . $md5; $cache = new CM_Cache_Storage_File(); if (false === ($contentMinified = $cache->get($cacheKey))) { $uglifyCommand = 'uglifyjs --no-copyright'; /** * Quote keys in literal objects, otherwise some browsers break. * E.g. "select2.js" on "Android 4.0.4" */ $uglifyCommand .= ' --beautify beautify=false,quote-keys=true'; $contentMinified = CM_Util::exec($uglifyCommand, null, $content); $cache->set($cacheKey, $contentMinified); } return $contentMinified; }
public function ajax_clearCache(CM_Params $params, CM_Frontend_JavascriptContainer_View $handler, CM_Http_Response_View_Ajax $response) { $cachesCleared = array(); if ($params->getBoolean('CM_Cache_Storage_Memcache', false)) { $cache = new CM_Cache_Storage_Memcache(); $cache->flush(); $cachesCleared[] = 'CM_Cache_Storage_Memcache'; } if ($params->getBoolean('CM_Cache_Storage_Apc', false)) { $cache = new CM_Cache_Storage_Apc(); $cache->flush(); $cachesCleared[] = 'CM_Cache_Storage_Apc'; } if ($params->getBoolean('CM_Cache_Storage_File', false)) { $cache = new CM_Cache_Storage_File(); $cache->flush(); $cachesCleared[] = 'CM_Cache_Storage_File'; } $handler->message('Cleared: ' . implode(', ', $cachesCleared)); }
/** * @return string */ protected function _getComposerVendorDir() { $fileComposerJson = new CM_File($this->_dirRoot . 'composer.json'); $cacheKey = CM_CacheConst::ComposerVendorDir; $fileCache = new CM_Cache_Storage_File(); if (false === ($vendorDir = $fileCache->get($cacheKey)) || $fileComposerJson->getModified() > $fileCache->getCreateStamp($cacheKey)) { $vendorDir = rtrim($this->getComposer()->getConfig()->get('vendor-dir'), '/') . '/'; $fileCache->set($cacheKey, $vendorDir); } return $vendorDir; }
/** * @param string $content * @param boolean $compress * @return string */ private function _compile($content, $compress) { $content = (string) $content; $compress = (bool) $compress; $cacheKey = CM_CacheConst::App_Resource . '_md5:' . md5($content); $cacheKey .= '_compress:' . (int) $compress; $cache = new CM_Cache_Storage_File(); if (false === ($contentTransformed = $cache->get($cacheKey))) { $contentTransformed = $content; $contentTransformed = $this->_compileLess($contentTransformed, $compress); $contentTransformed = $this->_compileAutoprefixer($contentTransformed); $contentTransformed = trim($contentTransformed); $cache->set($cacheKey, $contentTransformed); } return $contentTransformed; }
/** * @return array */ private function _getModulePaths() { $cacheKey = CM_CacheConst::Modules; $apcCache = new CM_Cache_Storage_Apc(); if (false === ($modulePaths = $apcCache->get($cacheKey))) { $fileCache = new CM_Cache_Storage_File(); $installation = new CM_App_Installation(DIR_ROOT); if ($installation->getUpdateStamp() > $fileCache->getCreateStamp($cacheKey) || false === ($modulePaths = $fileCache->get($cacheKey))) { $modulePaths = $installation->getModulePaths(); $fileCache->set($cacheKey, $modulePaths); } $apcCache->set($cacheKey, $modulePaths); } return $modulePaths; }