exists() 공개 메소드

Checks if a given key exists in the cache, valid for the given lifetime.
public exists ( string $key, integer $lifetime = 1 ) : boolean
$key string Cache key to check.
$lifetime integer Lifetime of the key in seconds.
리턴 boolean Existence.
예제 #1
0
파일: Base.php 프로젝트: raz0rsdge/horde
 /**
  * TODO
  *
  * @param array $opts  Options:
  * - 'file': (string) The filename to process.
  *           REQUIRED for this driver.
  * - 'range': (array) The patchsets to process.
  *            DEFAULT: None (all patchsets are processed).
  * - 'timezone': (string) The current timezone.
  *
  * @return Horde_Vcs_Patchset  Patchset object.
  */
 public function getPatchset($opts = array())
 {
     $class = 'Horde_Vcs_Patchset_' . $this->_driver;
     if (!is_array($opts)) {
         $opts = array();
     }
     ksort($opts);
     $cacheId = implode('|', array($class, $this->sourceroot, serialize($opts), $this->_cacheVersion));
     if (!empty($this->_cache)) {
         if (isset($opts['file']) && file_exists($opts['file'])) {
             $ctime = time() - filemtime($opts['file']);
         } else {
             $ctime = 60;
         }
         if ($this->_cache->exists($cacheId, $ctime)) {
             return unserialize($this->_cache->get($cacheId, $ctime));
         }
     }
     $ob = new $class($this, $opts);
     if (!empty($this->_cache)) {
         $this->_cache->set($cacheId, serialize($ob));
     }
     return $ob;
 }
예제 #2
0
파일: Registry.php 프로젝트: horde/horde
 /**
  * Load application information from registry config files.
  */
 protected function _loadApplications()
 {
     global $cli, $injector;
     if (!empty($this->_interfaces)) {
         return;
     }
     /* First, try to load from cache. */
     if (!isset($cli) && !$this->isTest()) {
         if (Horde_Util::extensionExists('apc')) {
             $cstorage = 'Horde_Cache_Storage_Apc';
         } elseif (Horde_Util::extensionExists('xcache')) {
             $cstorage = 'Horde_Cache_Storage_Xcache';
         } else {
             $cstorage = 'Horde_Cache_Storage_File';
         }
         $cache = new Horde_Cache(new $cstorage(array('no_gc' => true, 'prefix' => 'horde_registry_cache_')), array('lifetime' => 0, 'logger' => $injector->getInstance('Horde_Log_Logger')));
         if (($cid = $this->_cacheId()) && ($cdata = $cache->get($cid, 0))) {
             try {
                 list($this->applications, $this->_interfaces) = $injector->getInstance('Horde_Pack')->unpack($cdata);
                 return;
             } catch (Horde_Pack_Exception $e) {
             }
         }
     }
     $config = new Horde_Registry_Registryconfig($this);
     $this->applications = $config->applications;
     $this->_interfaces = $config->interfaces;
     if (!isset($cache)) {
         return;
     }
     /* Need to determine hash of generated data, since it is possible that
      * there is dynamic data in the config files. This only needs to
      * be done once per session. */
     $packed_data = $injector->getInstance('Horde_Pack')->pack(array($this->applications, $this->_interfaces));
     $cid = $this->_cacheId($packed_data);
     if (!$cache->exists($cid, 0)) {
         $cache->set($cid, $packed_data);
     }
 }