public function execute($filterChain) { // Create a function cache object for the QubitSettings method call $cache = new sfFileCache(array('cache_dir' => sfConfig::get('sf_app_cache_dir') . '/settings')); // Get settings (from cache if exists) if ($cache->has('settings')) { $settings = unserialize($cache->get('settings')); } else { $settings = QubitSetting::getSettingsArray(); $cache->set('settings', serialize($settings)); } // Overwrite/populate settings into sfConfig object sfConfig::add($settings); // Execute next filter $filterChain->execute(); }
protected function serve($file_info) { $cache = new sfFileCache(array('cache_dir' => sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . 'cache')); if ($file_info->getIsCached() && $cache->has($file_info->getId(), 'uploaded_files')) { $file_data = new FileData(); $file_data->setBinaryData($cache->get($file_info->getId(), 'uploaded_files')); } else { $file_data = $file_info->getFileData(); $cache->set($file_info->getId(), 'uploaded_files', fread($file_data->getBinaryData(), $file_info->getSize())); $file_info->setIsCached(true); $file_info->save(); } sfConfig::set('sf_web_debug', false); // $this->getResponse()->addHttpMeta('content-type', $file_info->getMime()); // $this->getResponse()->addHttpMeta('content-length', $file_info->getSize()); return $file_data; }
protected function serve() { //get an instance of the file cache object. We grab the web root then get the name of the cache folder //we don't want to use sf_cache_dir because that is application and environment specific //we don't want to a path relative to sf_web_dir because the sf_root_dir can be changed, better to start from there $cache = new sfFileCache(array('cache_dir' => sfConfig::get('sf_cache_dir') . "/" . sfCombineFilter::PACK_CACHE_FOLDER)); //Next we see if we can pull the file from the cache. if ($cache->has($this->cacheFileName)) { //Ok! We have a cached copy of the file! $this->data = $cache->get($this->cacheFileName); $this->mimeType = 'text/' . $this->type; $this->size = strlen($this->data); } else { //cached copy wasn't found, return 404 $this->forward404('Cache file not found!!! ' . $this->cacheFileName); } }
/** * Method to generate the final output of the collated files. It adds each * minified chunk to a file cache * * @param bool $minify (Optional) Whether to minify output * @param array $minifySkipSuffixes (Optional) if minify is allowed a * suffix of file endings to skip * (basically extensions like .min.js) * @param array $minifySkip (Optional) An array of filenames that * should not be minified * @return string */ protected function _generateOutput($minify = false, $minifySkipSuffixes = array(), $minifySkip = array()) { $minifiable = $this->_groupMinifableFiles($minify, $minifySkipSuffixes, $minifySkip, $this->getConfigOption('group_files', true)); $cache = false; if ($this->getConfigOption('cache_minified_files', false)) { $cache = new sfFileCache(array('cache_dir' => $this->getCacheDir())); } $output = ''; $fileNameComments = $this->getConfigOption('filename_comments', false); foreach ($minifiable as $files) { if ($fileNameComments) { if ($output) { $output .= PHP_EOL; } $output .= $this->_addFilenameComments($files['files']); } if (!$files['minify']) { $output .= $files['contents'] . PHP_EOL; } else { $minifiedContents = false; if ($cache) { $key = sha1($files['contents']); if ($cache->has($key)) { $minifedContents = $cache->get($key); } } if ($minifiedContents === false) { $minifiedContents = $this->minify($files['contents']); } $output .= $minifiedContents . PHP_EOL; if ($cache) { if (!$cache->has($key)) { $cache->set($key, $minifiedContents); } } } } return $output; }
/** * will not unserialize result */ public function _get($key, $default = null) { return parent::get($key, $default); }
/** * Take a db hash and convert it into an array of files * * @see getFiles */ public static function getFilesByKey($key, $separator = ' ') { $base64 = false; // try get base64 from cache if (function_exists('apc_store') && ini_get('apc.enabled')) { $cache = new sfAPCCache(); $base64 = $cache->get($key); } if (!$base64) { $cache = new sfFileCache(array('cache_dir' => sfCombineUtility::getCacheDir())); $base64 = $cache->get($key); } // check db if (!$base64 && class_exists('sfCombine')) { $combine = Doctrine::getTable('sfCombine')->find($key); $base64 = $combine ? $combine->getFiles() : false; } return self::getFilesByBase64($base64, $separator); }
/** * Tests if a cache is available and (if yes) returns it. * * @param string The cache id * @param string The name of the cache namespace * @param boolean If set to true, the cache validity won't be tested * * @return string Data of the cache (or null if no cache available) * * @see sfCache */ public function get($id, $namespace = self::DEFAULT_NAMESPACE, $doNotTestCacheValidity = false) { list($path, $file) = $this->getFileName($id, $namespace); try { if (!isset(self::$mem[$this->bucket])) { throw new Exception('This bucket was not setup in your memcache.yml'); } $std = self::$mem[$this->bucket]->get($path . $file); if ($std instanceof Stdclass) { return $std->data; } else { throw new Exception('Could not find cache'); } } catch (Exception $e) { return parent::get($id, $namespace, $doNotTestCacheValidity); } }
/** * @see sfFileCache::get() */ public function get($key, $default = null) { $data = parent::get($key, $default); return null === $data ? $default : unserialize($data); }