コード例 #1
0
ファイル: cache.php プロジェクト: davidmottet/automne
 /**
  * Constructor.
  * initialize object.
  *
  * @param string $hash the cache hash to use
  * @param string $type : the type of the cache to use
  * @param mixed $lifetime : the cache lifetime
  * @return void
  * @access public
  */
 function __construct($hash, $type, $lifetime = null, $contextAware = false)
 {
     if ($contextAware) {
         $this->_parameters['hash'] = $hash . '_' . CMS_session::getContextHash();
         $this->_context = true;
     } else {
         $this->_parameters['hash'] = $hash;
     }
     //normalize cache lifetime
     if ($lifetime == 'false' || $lifetime == '0' || $lifetime === false || $lifetime === 0) {
         $lifetime = false;
     }
     if ($lifetime == 'true' || $lifetime == 'auto' || $lifetime == '1' || $lifetime === true || $lifetime === 1) {
         //this definition do not use PHP so use default cache lifetime
         $lifetime = CACHE_MODULES_DEFAULT_LIFETIME;
         //set this cache as auto lifetime
         $this->_auto = true;
     }
     if (io::isPositiveInteger($lifetime)) {
         $lifetime = (int) $lifetime;
     }
     $this->_parameters['type'] = io::sanitizeAsciiString($type);
     $this->_parameters['lifetime'] = $lifetime ? $lifetime : null;
     //check cache dir
     $cachedir = new CMS_file(PATH_CACHE_FS . '/' . $this->_parameters['type'], CMS_file::FILE_SYSTEM, CMS_file::TYPE_DIRECTORY);
     if (!$cachedir->exists()) {
         $cachedir->writeTopersistence();
     }
     //Cache options
     $frontendOptions = array('lifetime' => $this->_parameters['lifetime'], 'caching' => $this->_parameters['lifetime'] === null ? false : CACHE_MODULES_DATAS, 'automatic_cleaning_factor' => 50, 'automatic_serialization' => true);
     $backendOptions = array('cache_dir' => PATH_CACHE_FS . '/' . $this->_parameters['type'], 'cache_file_umask' => octdec(FILES_CHMOD), 'hashed_directory_umask' => octdec(DIRS_CHMOD), 'hashed_directory_level' => 2);
     // getting a Zend_Cache_Core object
     if (!class_exists('Zend_Cache')) {
         die('not found ....');
     }
     try {
         $this->_cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
     } catch (Zend_Cache_Exception $e) {
         $this->raiseError($e->getMessage());
         return false;
     }
     if (!isset($this->_cache) || !is_object($this->_cache)) {
         $this->raiseError('Error : Zend cache object does not exists');
         return false;
     }
 }
コード例 #2
0
ファイル: context.php プロジェクト: davidmottet/automne
 /**
  * Get current context hash (usually used for cache)
  *
  * @param array $datas, additionnal datas to use for cache
  * @return string : the current context cache
  * @access public
  * @static
  */
 static function getContextHash($datas = array())
 {
     return CMS_session::getContextHash($datas);
 }