コード例 #1
0
ファイル: cache.php プロジェクト: Kheros/MMOver
 /**
  * Writes data as a cache object.
  *
  * A string key is required to uniquely identify a cache object.  Client
  * code should add all information that would affect the individualisation of
  * the cache object to the key.
  *
  * If lifetime_mins is supplied the cache object will be purged the next time it
  * is read after the TTL has passed.
  *
  * If a cache object should be purged on triggered events then events should be
  * supplied as an array of string id's of the form 'scope.event', for example
  * 'widget55.updated' may be used to purge a cache of a defined widget with the
  * id 55 when it is reconfigured.
  *
  * Note: To use events, a cacheObserver event handler must be registered first.
  * @see cache::attachObserver()
  *
  * @param string $key						- Identifying key
  * @param mixed $data						- Data to cache
  * @param int $lifetime						- Lifetime of cache, in minutes
  * @param array string $events				- Purge events to associate with the cache object
  * @return int | bool						- Cache id or false
  */
 public function write($key, $data, $lifetime_mins = false, $events = false)
 {
     // Check if caching is disabled, usually for debugging
     if (vB::$vbulletin->options['nocache']) {
         return false;
     }
     // If data is empty then there's nothing to write
     if (!$data) {
         return false;
     }
     // Wrap data in a cache object
     $cache = new vB_CacheObject($key, $data);
     if ($lifetime_mins) {
         $cache->setExpiry(TIMENOW + $lifetime_mins * 60);
     }
     // Write the cache object
     $this->writeCache($cache);
     // Notify observers of cache write and events
     $this->notifyWritten($key, $events);
     // Unlock the cache entry
     $this->unlock($key);
     $this->values_read[$key] = $data;
     //need to clear no_values for this key
     if (isset($this->no_values[$key])) {
         unset($this->no_values[$key]);
     }
     return $cache->getKey();
 }