示例#1
0
 /**
  * Save data to memcached, split it into chunks if data size is bigger than memcached slab size.
  *
  * @param string $data             @see \Zend_Cache_Backend_Memcached::save()
  * @param string $id               @see \Zend_Cache_Backend_Memcached::save()
  * @param string[] $tags           @see \Zend_Cache_Backend_Memcached::save()
  * @param bool $specificLifetime   @see \Zend_Cache_Backend_Memcached::save()
  * @return bool
  */
 public function save($data, $id, $tags = [], $specificLifetime = false)
 {
     if (is_string($data) && strlen($data) > $this->_options['slab_size']) {
         $dataChunks = str_split($data, $this->_options['slab_size']);
         for ($i = 0, $cnt = count($dataChunks); $i < $cnt; $i++) {
             $chunkId = $this->_getChunkId($id, $i);
             if (!parent::save($dataChunks[$i], $chunkId, $tags, $specificLifetime)) {
                 $this->_cleanTheMess($id, $i + 1);
                 return false;
             }
         }
         $data = self::CODE_WORD . '|' . $i;
     }
     return parent::save($data, $id, $tags, $specificLifetime);
 }
示例#2
0
 /**
  * Save some string datas into a cache record
  *
  * Note : $data is always "string" (serialization is done by the
  * core not by the backend)
  *
  * @param  string $data             Datas to cache
  * @param  string $id               Cache id
  * @param  array  $tags             Array of strings, the cache record will be tagged by each string entry
  * @param  int    $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
  * @return boolean True if no problem
  */
 public function save($data, $id, $tags = array(), $specificLifetime = false)
 {
     $this->checkCacheConsistency();
     $result = parent::save($data, $id, array(), $specificLifetime);
     if ($result) {
         if (count($tags) > 0) {
             $this->saveTags($id, $tags);
         }
     } else {
         $this->remove($id);
     }
     return $result;
 }
示例#3
0
文件: App.php 项目: FTeichmann/Erfurt
 /**
  * Returns a cache backend as configured.
  *
  * @return Zend_Cache_Backend
  * @throws Erfurt_Exception
  */
 private function _getCacheBackend()
 {
     if (null === $this->_cacheBackend) {
         $config = $this->getConfig();
         // check the type an whether type is supported
         $cacheType = $config->cache->backend->type;
         // caching is not enabled, use fake cache backend
         if (!$config->cache->frontend->enable) {
             $cacheType = "null";
         }
         switch (strtolower($cacheType)) {
             case 'memcached':
                 $options = $config->cache->backend->memcached->toArray();
                 $cache = new Zend_Cache_Backend_Memcached($options);
                 if (!$cache->save(time(), 'EF_lastConnect')) {
                     throw new Erfurt_Exception('Memcache server is not available.');
                 }
                 break;
             case 'apc':
                 $cache = new Zend_Cache_Backend_Apc();
                 break;
             case 'sqlite':
                 $options = $config->cache->backend->sqlite->toArray();
                 if (!in_array('cache_db_complete_path', array_keys($options))) {
                     throw new Erfurt_Exception('Cache database filename must be set for sqlite cache backend (cache_db_complete_path).');
                 }
                 $cache = new Zend_Cache_Backend_Sqlite($options);
                 break;
             case 'file':
                 $path = $config->cache->backend->file->cache_dir;
                 if (!$path) {
                     throw new Erfurt_App_Exception('No cache directory configured.');
                 }
                 if (!file_exists($path)) {
                     throw new Erfurt_App_Exception('Cache directory "' . $path . '" is not existing.');
                 }
                 if (!is_writable($path)) {
                     throw new Erfurt_App_Exception('Cache directory "' . $path . '" is not writable.');
                 }
                 $options = $config->cache->backend->file->toArray();
                 $cache = new Zend_Cache_Backend_File($options);
                 break;
             case 'database':
                 $cache = new Erfurt_Cache_Backend_Database();
                 break;
             case 'null':
                 $cache = new Erfurt_Cache_Backend_Null();
                 break;
             default:
                 throw new Erfurt_Exception('Cache type "' . $cacheType . '" is not supported.');
         }
         $this->_cacheBackend = $cache;
     }
     return $this->_cacheBackend;
 }
 public function save($data, $id, $tags = array(), $specificLifetime = false)
 {
     $id = $this->_processId($id);
     try {
         return parent::save($data, $id, $tags, $specificLifetime);
     } catch (ErrorException $e) {
         if ($e->getSeverity() == E_NOTICE) {
             $e = new Kwf_Exception_Other($e);
             $e->logOrThrow();
             return false;
         }
         throw $e;
     }
 }
 public function save($data, $id, $tags = array(), $specificLifetime = false)
 {
     return parent::save($data, $this->_makeId($id), $tags, $specificLifetime);
 }