/** * Saves some data in a cache file. * * This function handles generating the cached php code for the array. * * @param string The cache id * @param string The name of the cache namespace * @param array The array to put in cache * * @return boolean true if no problem * * @see sfCache */ public function set($id, $namespace = self::DEFAULT_NAMESPACE, $array) { $data = array(); $data[] = '<?php'; $data[] = '// auto-generated by sfArrayCache'; $data[] = '// date: ' . date('Y-m-d H:i:s'); $data[] = ''; $data[] = 'return ' . var_export($array, true) . ';'; return parent::set($id, $namespace, implode("\n", $data)); }
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; }
/** * Writes a cache file. * * @param string An absolute filesystem path to a configuration file * @param string An absolute filesystem path to the cache file that will be written * @param string Data to be written to the cache file * * @throws sfCacheException If the cache file cannot be written */ protected function writeCacheFile($config, $cache, &$data) { $fileCache = new sfFileCache(dirname($cache)); $fileCache->initialize(array('lifeTime' => 86400 * 365 * 10, 'automaticCleaningFactor' => 0)); $fileCache->setWriteControl(true); $fileCache->setSuffix(''); if (!$fileCache->set(basename($cache), '', $data)) { $fileCache->remove(basename($cache), ''); throw new sfConfigurationException(sprintf('Unable to write config cache for "%s".', $config)); } }
/** * Writes a cache file. * * @param string An absolute filesystem path to a configuration file * @param string An absolute filesystem path to the cache file that will be written * @param string Data to be written to the cache file * * @throws sfCacheException If the cache file cannot be written */ protected function writeCacheFile($config, $cache, &$data) { $fileCache = new sfFileCache(dirname($cache)); $fileCache->setSuffix(''); $fileCache->set(basename($cache), '', $data); }
/** * 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 serialize result */ public function _set($key, $data, $lifetime = null) { return parent::set($key, $data, $lifetime); }
/** * Return a hash which refers to an entry in the db describing the files * * @see getFileString */ public static function getKey(array $files, $separator = ' ') { $content = self::getBase64($files, $separator); $key = sha1($content); $check = false; if (function_exists('apc_store') && ini_get('apc.enabled')) { $cache = new sfAPCCache(); $check = $cache->has($key); } else { $cache = new sfFileCache(array('cache_dir' => sfCombineUtility::getCacheDir())); $check = $cache->has($key); } // Checks if key exists if (false === $check) { // now just doctrine if (!class_exists('sfCombine')) { throw new Exception('Call the task `doctrine:build-model` or use base64 url'); } $keyExists = Doctrine::getTable('sfCombine')->find($key); if (!$keyExists) { $combine = new sfCombine(); $combine->setAssetKey($key); $combine->setFiles($content); $combine->save(); } $cache->set($key, $content); } return $key; }
/** * Saves some data in a cache file. * * @param string The cache id * @param string The name of the cache namespace * @param string The data to put in cache * * @return boolean true if no problem * * @see sfCache */ public function set($id, $namespace = self::DEFAULT_NAMESPACE, $data) { list($path, $file) = $this->getFileName($id, $namespace); try { $std = new Stdclass(); $std->data = $data; $std->lastModified = time(); $internalUri = sfRouting::getInstance()->getCurrentInternalUri(); $lifeTime = $this->getLifeTime(); sfLogger::getInstance()->info("xxx: {$internalUri} - {$lifeTime}"); if (!isset(self::$mem[$this->bucket])) { throw new Exception('This bucket was not setup correctly'); } if (!self::$mem[$this->bucket]->set($path . $file, $std, false, $lifeTime)) { throw new Exception('Could not save in memcache'); } } catch (Exception $e) { return parent::set($id, $namespace, $data); } }
/** * @see sfFileCache::set() */ public function set($key, $data, $lifetime = null) { return parent::set($key, serialize($data), $lifetime); }
/** * Returns a key which combined all assets file * * @return string md5 */ function _get_key($files) { $content = base64_encode(serialize($files)); $key = md5($content . sfConfig::get('app_sfCombinePlugin_asset_version', '')); if (!class_exists('DbFinder')) { throw new Exception('sfCombine expects DbFinder to call combined asset file'); } if (function_exists('apc_store') && ini_get('apc.enabled')) { $cache = new sfAPCCache(); // FIXME: APCCache "has" method doesn't work $checkFunction = apc_fetch($key); } else { $cache = new sfFileCache(array('cache_dir' => sfConfig::get('sf_cache_dir') . '/combiners')); $checkFunction = $cache->has($key); } // Checks if key exists if (false === $checkFunction) { $keyExists = DbFinder::from('sfCombine')->where('AssetsKey', $key)->count(); if (!$keyExists) { $combine = new sfCombine(); $combine->setAssetsKey($key); $combine->setFiles($content); $combine->save(); } $cache->set($key, true); } return $key; }
/** * Return a hash which refers to an entry in the db describing the files * * Based off the sfCombine _getKey method * * @see getFileString */ public static function getKey(array $files, $separator = ' ') { $content = self::getBase64($files, $separator); $key = sha1($content); $check = false; if (function_exists('apc_store') && ini_get('apc.enabled')) { $cache = new sfAPCCache(); $check = $cache->has($key); } else { $cache = new sfFileCache(array('cache_dir' => sfCombinePlusUtility::getCacheDir())); $check = $cache->has($key); } // Checks if key exists if (false === $check) { // now just doctrine $keyExists = sfCombinePlus::hasKey($key); if (!$keyExists) { $combine = new sfCombinePlus(); $combine->setAssetKey($key); $combine->setFiles($content); $combine->save(); } $cache->set($key, $content); } return $key; }