當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Environment::enterCriticalSection方法代碼示例

本文整理匯總了PHP中Nette\Environment::enterCriticalSection方法的典型用法代碼示例。如果您正苦於以下問題:PHP Environment::enterCriticalSection方法的具體用法?PHP Environment::enterCriticalSection怎麽用?PHP Environment::enterCriticalSection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Nette\Environment的用法示例。


在下文中一共展示了Environment::enterCriticalSection方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: save

 /**
  * Writes item into the cache.
  * Dependencies are:
  * - Cache::PRIORITY => (int) priority
  * - Cache::EXPIRE => (timestamp) expiration
  * - Cache::SLIDING => (bool) use sliding expiration?
  * - Cache::TAGS => (array) tags
  * - Cache::FILES => (array|string) file names
  * - Cache::ITEMS => (array|string) cache items
  * - Cache::CONSTS => (array|string) cache items
  *
  * @param  string key
  * @param  mixed  value
  * @param  array  dependencies
  * @return mixed  value itself
  * @throws \InvalidArgumentException
  */
 public 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;
     // convert expire into relative amount of seconds
     if (!empty($dp[Cache::EXPIRE])) {
         $dp[Cache::EXPIRE] = Nette\Tools::createDateTime($dp[Cache::EXPIRE])->format('U') - time();
     }
     // convert FILES into CALLBACKS
     if (isset($dp[self::FILES])) {
         //clearstatcache();
         foreach ((array) $dp[self::FILES] as $item) {
             $dp[self::CALLBACKS][] = array(array(__CLASS__, 'checkFile'), $item, @filemtime($item));
             // @ - stat may fail
         }
         unset($dp[self::FILES]);
     }
     // add namespaces to items
     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;
         }
     }
     // convert CONSTS into CALLBACKS
     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 Nette\Callback || $data instanceof \Closure) {
         Nette\Environment::enterCriticalSection('Nette\\Caching/' . $key);
         $data = $data->__invoke();
         Nette\Environment::leaveCriticalSection('Nette\\Caching/' . $key);
     }
     if (is_object($data)) {
         $dp[self::CALLBACKS][] = array(array(__CLASS__, 'checkSerializationVersion'), get_class($data), Nette\Reflection\ClassReflection::from($data)->getAnnotation('serializationVersion'));
     }
     $this->data = $data;
     if ($data === NULL) {
         $this->storage->remove($key);
     } else {
         $this->storage->write($key, $data, (array) $dp);
     }
     return $data;
 }
開發者ID:jakubkulhan,項目名稱:nette,代碼行數:67,代碼來源:Cache.php


注:本文中的Nette\Environment::enterCriticalSection方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。