当前位置: 首页>>代码示例>>PHP>>正文


PHP apcu_add函数代码示例

本文整理汇总了PHP中apcu_add函数的典型用法代码示例。如果您正苦于以下问题:PHP apcu_add函数的具体用法?PHP apcu_add怎么用?PHP apcu_add使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了apcu_add函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: set

 public function set(string $key, string $value, int $life = 3600) : bool
 {
     if ($life == 0) {
         $life = null;
     }
     return apcu_add($key, $value, $life);
 }
开发者ID:knowsee,项目名称:uoke_framework,代码行数:7,代码来源:apcu.class.php

示例2: cacheData

 public function cacheData($key, $data, $timeCache = null)
 {
     if (apcu_exists($key)) {
         return apcu_fetch($key, false);
     } else {
         if (!empty($timeCache)) {
             apcu_add($key, $data, $timeCache);
         } else {
             apcu_add($key, $data, $this->timeCache);
         }
     }
 }
开发者ID:drivesoftz,项目名称:post-app-basic,代码行数:12,代码来源:APCCache.php

示例3: set

 /**
  * {@inheritdoc}
  *
  * @return \Orno\Cache\Adapter\Apc
  */
 public function set($key, $data, $expiry = null)
 {
     if (is_null($expiry)) {
         $expiry = $this->getExpiry();
     }
     if (is_string($expiry)) {
         $expiry = $this->convertExpiryString($expiry);
     }
     if ($this->apcu) {
         apcu_add($key, $data, $expiry);
     } else {
         apc_add($key, $data, $expiry);
     }
     return $this;
 }
开发者ID:orno,项目名称:cache,代码行数:20,代码来源:ApcAdapter.php

示例4: __construct

 public function __construct($namespace = '', $defaultLifetime = 0, $version = null)
 {
     if (!static::isSupported()) {
         throw new CacheException('APCu is not enabled');
     }
     if ('cli' === PHP_SAPI) {
         ini_set('apc.use_request_time', 0);
     }
     parent::__construct($namespace, $defaultLifetime);
     if (null !== $version) {
         CacheItem::validateKey($version);
         if (!apcu_exists($version . ':' . $namespace)) {
             $this->clear($namespace);
             apcu_add($version . ':' . $namespace, null);
         }
     }
 }
开发者ID:unexge,项目名称:symfony,代码行数:17,代码来源:ApcuAdapter.php

示例5: addVote

 public function addVote(Request $request)
 {
     $object = $this->getObject($request->get('id'), $request->get('type'));
     if (!$object) {
         return response()->make('Object not found', 404);
     }
     if ($this->getVoteElement($object, Auth::user())) {
         return response()->make('Already voted', 400);
     }
     if ($object->user->getKey() == Auth::id()) {
         return response()->make('Do not cheat', 400);
     }
     if ($object instanceof ContentRelated) {
         $group = $object->content->group;
     } else {
         $group = $object->group;
     }
     if (Auth::user()->isBanned($group)) {
         return response()->make('Banned', 400);
     }
     if (!apcu_add('anti_vote_flood.user.' . Auth::id(), 1, 1)) {
         return response()->make('Don\'t flood', 400);
     }
     $uv = $object->uv;
     $dv = $object->dv;
     $up = request('up') === 'true';
     if ($up) {
         $object->increment('uv');
         $object->increment('score');
         // small hack, as increment function doesn't update object :(
         $uv++;
         // small trigger, needed for pushing contents to front page
         if ($object instanceof Content && !$object->frontpage_at && $object->uv > config('strimoid.homepage.threshold') && $object->created_at->diffInDays() < config('strimoid.homepage.time_limit')) {
             $object->frontpage_at = new Carbon();
             $object->save();
         }
     } else {
         $object->increment('dv');
         $object->decrement('score');
         $dv++;
     }
     $object->votes()->create(['created_at' => new Carbon(), 'user_id' => Auth::id(), 'up' => $up]);
     return response()->json(['status' => 'ok', 'uv' => $uv, 'dv' => $dv]);
 }
开发者ID:strimoid,项目名称:strimoid,代码行数:44,代码来源:VoteController.php

示例6: testApcu

 public function testApcu()
 {
     $key = __CLASS__;
     apcu_delete($key);
     $this->assertFalse(apcu_exists($key));
     $this->assertTrue(apcu_add($key, 123));
     $this->assertTrue(apcu_exists($key));
     $this->assertSame(array($key => -1), apcu_add(array($key => 123)));
     $this->assertSame(123, apcu_fetch($key));
     $this->assertTrue(apcu_store($key, 124));
     $this->assertSame(124, apcu_fetch($key));
     $this->assertSame(125, apcu_inc($key));
     $this->assertSame(124, apcu_dec($key));
     $this->assertTrue(apcu_cas($key, 124, 123));
     $this->assertFalse(apcu_cas($key, 124, 123));
     $this->assertTrue(apcu_delete($key));
     $this->assertFalse(apcu_delete($key));
     $this->assertArrayHasKey('cache_list', apcu_cache_info());
 }
开发者ID:derrabus,项目名称:polyfill,代码行数:19,代码来源:ApcuTest.php

示例7: cache_Create

 function cache_Create($key, $value = null, $ttl = 0)
 {
     global $CACHE_STORE_COUNT;
     $CACHE_STORE_COUNT++;
     return apcu_add($key, $value, $ttl);
 }
开发者ID:LastResortGames,项目名称:ludumdare,代码行数:6,代码来源:cache.php

示例8: add

 /**
  * {@inheritdoc}
  */
 public function add($key, $value, $ttl = 0)
 {
     $res = apcu_add($key, $value, $ttl);
     return $res;
 }
开发者ID:sugiphp,项目名称:cache,代码行数:8,代码来源:ApcuStore.php

示例9: lock

 /**
  * Lock cached item
  *
  * @param   string   $key The cache data key
  * @param   string   $group The cache data group
  * @param   integer  $locktime Cached item max lock time
  *
  * @return  boolean
  *
  * @since   1.2.7
  */
 public function lock($key, $group, $locktime)
 {
     $output = array();
     $output['waited'] = false;
     $looptime = $locktime * 10;
     $cache_key = $this->_getCacheId($key, $group) . '_lock';
     $data_lock = apcu_add($cache_key, 1, $locktime);
     if ($data_lock === false) {
         $lock_counter = 0;
         // Loop until you find that the lock has been released. That implies that data get from other thread has finished
         while ($data_lock === false) {
             if ($lock_counter > $looptime) {
                 $output['locked'] = false;
                 $output['waited'] = true;
                 break;
             }
             usleep(100);
             $data_lock = apcu_add($cache_key, 1, $locktime);
             $lock_counter++;
         }
     }
     $output['locked'] = $data_lock;
     return $output;
 }
开发者ID:siddht1,项目名称:abantecart-src,代码行数:35,代码来源:apcu.php

示例10: apcu_add

 /**
  * @param string|string[] $key
  * @param mixed           $var
  * @param int             $ttl
  *
  * @return bool|bool[]
  */
 protected function apcu_add($key, $var, $ttl = 0)
 {
     if (function_exists('apcu_add')) {
         return apcu_add($key, $var, $ttl);
     } else {
         return apc_add($key, $var, $ttl);
     }
 }
开发者ID:matthiasmullie,项目名称:scrapbook,代码行数:15,代码来源:Apc.php

示例11: withMemory

 /**
  * Try to cache the callback result in APCU
  * @param type $name
  * @param \Blend\Component\Cache\callable $callback
  * @return mixed
  */
 private function withMemory($name, callable $callback)
 {
     if (apcu_exists($name)) {
         $success = false;
         $result = apcu_fetch($name, $success);
         if ($success) {
             return $result;
         } else {
             $this->logger->warning('APCU cache did not return correctly!', ['cache' => $name]);
             return call_user_func($callback);
         }
     } else {
         $result = call_user_func($callback);
         if (!apcu_add($name, $result)) {
             $this->logger->warning("Unable to store data in cache!", ['data' => $result]);
         }
         return $result;
     }
 }
开发者ID:blendsdk,项目名称:blendengine,代码行数:25,代码来源:LocalCache.php

示例12: add

 public function add($key, $value, $seconds = 0)
 {
     $key = $this->prefix . $key;
     return $this->apcu ? apcu_add($key, $value, $seconds) : apc_add($key, $value, $seconds);
 }
开发者ID:saoyor,项目名称:php-framework,代码行数:5,代码来源:Apc.php

示例13: internalDecrementItem

 /**
  * Internal method to decrement an item.
  *
  * @param  string $normalizedKey
  * @param  int    $value
  * @return int|bool The new value on success, false on failure
  * @throws Exception\ExceptionInterface
  */
 protected function internalDecrementItem(&$normalizedKey, &$value)
 {
     $options = $this->getOptions();
     $namespace = $options->getNamespace();
     $prefix = $namespace === '' ? '' : $namespace . $options->getNamespaceSeparator();
     $internalKey = $prefix . $normalizedKey;
     $value = (int) $value;
     $newValue = apcu_dec($internalKey, $value);
     // initial value
     if ($newValue === false) {
         $ttl = $options->getTtl();
         $newValue = -$value;
         if (!apcu_add($internalKey, $newValue, $ttl)) {
             throw new Exception\RuntimeException("apcu_add('{$internalKey}', {$newValue}, {$ttl}) failed");
         }
     }
     return $newValue;
 }
开发者ID:stephenmoore56,项目名称:mooredatabase-laravel,代码行数:26,代码来源:Apcu.php

示例14: addValues

 /**
  * Adds multiple key-value pairs to cache.
  * @param array $data array where key corresponds to cache key while value is the value stored
  * @param integer $duration the number of seconds in which the cached values will expire. 0 means never expire.
  * @return array array of failed keys
  */
 protected function addValues($data, $duration)
 {
     $result = $this->useApcu ? apcu_add($data, null, $duration) : apc_add($data, null, $duration);
     return is_array($result) ? array_keys($result) : [];
 }
开发者ID:Kest007,项目名称:yii2,代码行数:11,代码来源:ApcCache.php

示例15: apc_add

 function apc_add($key, $var, $ttl = 0)
 {
     return apcu_add($key, $var, $ttl);
 }
开发者ID:lavoiesl,项目名称:apc-polyfill,代码行数:4,代码来源:polyfill.php


注:本文中的apcu_add函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。