示例#1
0
文件: loader.php 项目: GE3/GE3
 function save($key, $data, array $dp = NULL)
 {
     if (!is_string($key) && !is_int($key)) {
         throw new InvalidArgumentException("Cache key name must be string or integer, " . gettype($key) . " given.");
     }
     $this->key = (string) $key;
     $key = $this->namespace . self::NAMESPACE_SEPARATOR . $key;
     if (!empty($dp[NCache::EXPIRE])) {
         $dp[NCache::EXPIRE] = NTools::createDateTime($dp[NCache::EXPIRE])->format('U') - time();
     }
     if (isset($dp[self::FILES])) {
         foreach ((array) $dp[self::FILES] as $item) {
             $dp[self::CALLBACKS][] = array(array(__CLASS__, 'checkFile'), $item, @filemtime($item));
         }
         unset($dp[self::FILES]);
     }
     if (isset($dp[self::ITEMS])) {
         $dp[self::ITEMS] = (array) $dp[self::ITEMS];
         foreach ($dp[self::ITEMS] as $k => $item) {
             $dp[self::ITEMS][$k] = $this->namespace . self::NAMESPACE_SEPARATOR . $item;
         }
     }
     if (isset($dp[self::CONSTS])) {
         foreach ((array) $dp[self::CONSTS] as $item) {
             $dp[self::CALLBACKS][] = array(array(__CLASS__, 'checkConst'), $item, constant($item));
         }
         unset($dp[self::CONSTS]);
     }
     if ($data instanceof NCallback || $data instanceof Closure) {
         NEnvironment::enterCriticalSection('Nette\\Caching/' . $key);
         $data = $data->__invoke();
         NEnvironment::leaveCriticalSection('Nette\\Caching/' . $key);
     }
     if (is_object($data)) {
         $dp[self::CALLBACKS][] = array(array(__CLASS__, 'checkSerializationVersion'), get_class($data), NClassReflection::from($data)->getAnnotation('serializationVersion'));
     }
     $this->data = $data;
     if ($data === NULL) {
         $this->storage->remove($key);
     } else {
         $this->storage->write($key, $data, (array) $dp);
     }
     return $data;
 }