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


PHP Cache::increment方法代码示例

本文整理汇总了PHP中Cache::increment方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::increment方法的具体用法?PHP Cache::increment怎么用?PHP Cache::increment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cache的用法示例。


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

示例1: Cache

 function test_incr_decr()
 {
     $c = new Cache();
     $this->assertTrue($c->set('foo', 0));
     $this->assertEquals($c->increment('foo'), 1);
     $this->assertEquals($c->increment('foo'), 2);
     $this->assertEquals($c->increment('foo', 2), 4);
     $this->assertEquals($c->decrement('foo'), 3);
     $this->assertEquals($c->get('foo'), 3);
 }
开发者ID:Selwyn-b,项目名称:elefant,代码行数:10,代码来源:CacheTest.php

示例2: increateCount

 public function increateCount($key, $inc = 1)
 {
     $result = $this->cache->increment($key, $inc);
     if ($result === false) {
         if ($this->cache->set($key, $inc, 0) === false) {
             return false;
         } else {
             return $inc;
         }
     }
     return $result;
 }
开发者ID:GameCrusherTechnology,项目名称:HeroTowerServer,代码行数:12,代码来源:MemCounter.class.php

示例3: put

 /**
  * pushes identify key to cache
  *
  * @param     $ident
  * @param int $minutes
  */
 public function put($ident, $minutes = 10)
 {
     if (!$ident || !is_numeric($minutes)) {
         return;
     }
     $key = 'af:' . $ident;
     if (\Cache::has($key) && is_numeric(\Cache::get($key))) {
         \Cache::increment($key);
     } else {
         \Cache::put($key, 1, $minutes);
     }
 }
开发者ID:ircop,项目名称:antiflood,代码行数:18,代码来源:Antiflood.php

示例4: updateCache

 private function updateCache($inc = 1)
 {
     $key = $this->getMemKey();
     $key_next = $key . '_next_value';
     $this->initSeq($this->id_field);
     $seq = $this->cache->increment($key, $inc);
     $next_value = $this->cache->get($key_next);
     if ($seq >= $next_value) {
         $this->commitData($seq);
         $this->cache->increment($key_next, $this->step);
     }
     return $seq;
 }
开发者ID:GameCrusherTechnology,项目名称:HeroTowerServer,代码行数:13,代码来源:IDSequence.class.php

示例5: counterIncrement

 public function counterIncrement($id)
 {
     if (Configure::read('debug') === 0 && $_SERVER['HTTP_HOST'] !== 'localhost') {
         $cacheKey = "{$this->name}/Counter/{$id}";
         $cachedCounter = Cache::read($cacheKey);
         if (false === Cache::increment($cacheKey) || false === $cachedCounter) {
             Cache::write($cacheKey, 1);
         }
         if ((int) $cachedCounter >= 10) {
             Cache::write($cacheKey, 1);
             $this->updateAll(array('count_daily' => "count_daily + {$cachedCounter}", 'count_all' => "count_all + {$cachedCounter}"), array("{$this->name}.id" => $id));
         }
     }
 }
开发者ID:rungrr,项目名称:drugs,代码行数:14,代码来源:AppModel.php

示例6: store

 public function store(Request $request)
 {
     $title = $request->input('title');
     $content = $request->input('content');
     $post = ['title' => trim($title), 'content' => trim($content)];
     $posts = Cache::get('posts', []);
     if (!Cache::get('post_id')) {
         Cache::add('post_id', 1, 60);
     } else {
         Cache::increment('post_id', 1);
     }
     $posts[Cache::increment('post_id', 1)];
     Cache::put('posts', $posts, 60);
     return redirect()->route('post.show', ['post' => Cache::get('post_id')]);
 }
开发者ID:Graychen,项目名称:quickstart_laravel,代码行数:15,代码来源:PostController.php

示例7: start

 public static function start()
 {
     $key = static::getKey();
     $start = microtime(true);
     Cache::add($key, 0, static::$intervalSeconds);
     register_shutdown_function('Firewall::end');
     while (Cache::increment($key) > static::$concurrency) {
         Cache::decrement($key);
         if (!static::$spinLockSeconds || microtime(true) - $start > static::$intervalSeconds) {
             http_response_code(429);
             die('429: Too Many Requests');
         }
         usleep(static::$spinLockSeconds * 1000000);
     }
 }
开发者ID:mehulsbhatt,项目名称:MindaPHP,代码行数:15,代码来源:Firewall.php

示例8: postLogin

 public function postLogin(Request $request)
 {
     $valid = Validator::make($request->all(), ['name' => 'required', 'password' => 'required']);
     if ($valid->fails()) {
         return redirect()->back()->withErrors($valid)->withInput();
     }
     if (\Cache::has('loginAttempt')) {
         $attempt_count = \Cache::get('loginAttempt');
         if ($attempt_count > 3) {
             return redirect()->back()->with('errorMess', 'Bạn đã đăng nhập sai quá nhiều lần, Vui lòng thử lại sau 1 giờ nữa');
         }
         \Cache::increment('loginAttempt');
     } else {
         \Cache::put('loginAttempt', 1, 60);
     }
     if (auth()->attempt(['name' => $request->input('name'), 'password' => $request->input('password'), 'active' => 1])) {
         \Cache::forget('loginAttempt');
         return redirect()->route('admin.index');
     }
     return redirect()->back()->withInput()->with('errorMess', trans('Tên đăng nhập hoặc mật khẩu không đúng'));
 }
开发者ID:JamesNguyen9x,项目名称:vatc,代码行数:21,代码来源:AdminController.php

示例9: testIncrement

 /**
  * testIncrement method
  *
  * @return void
  */
 public function testIncrement()
 {
     $result = Cache::write('test_increment', 5, 'memcache');
     $this->assertTrue($result);
     $result = Cache::increment('test_increment', 1, 'memcache');
     $this->assertEqual(6, $result);
     $result = Cache::read('test_increment', 'memcache');
     $this->assertEqual(6, $result);
     $result = Cache::increment('test_increment', 2, 'memcache');
     $this->assertEqual(8, $result);
     $result = Cache::read('test_increment', 'memcache');
     $this->assertEqual(8, $result);
 }
开发者ID:nabeelio,项目名称:CakePHP-Base,代码行数:18,代码来源:MemcacheTest.php

示例10: testIncrement

 /**
  * testIncrement method
  *
  * @access public
  * @return void
  */
 function testIncrement()
 {
     if ($this->skipIf(!function_exists('apc_inc'), 'No apc_inc() function, cannot test increment() %s')) {
         return;
     }
     $result = Cache::write('test_increment', 5);
     $this->assertTrue($result);
     $result = Cache::increment('test_increment');
     $this->assertEqual(6, $result);
     $result = Cache::read('test_increment');
     $this->assertEqual(6, $result);
     $result = Cache::increment('test_increment', 2);
     $this->assertEqual(8, $result);
     $result = Cache::read('test_increment');
     $this->assertEqual(8, $result);
 }
开发者ID:arendasistemasintegrados,项目名称:mateusleme,代码行数:22,代码来源:apc.test.php

示例11: applyThrottle

 /**
  * Throttle on the basis of source type
  *
  * @param array $definition
  *
  * @return Response
  */
 private function applyThrottle($definition)
 {
     if ($definition['source_type'] == 'ElasticsearchDefinition') {
         $requestsPerHour = 720;
         // Rate limit by IP address
         $key = sprintf('api:%s', \Request::getClientIp());
         // Add if doesn't exist
         // Remember for 1 hour
         \Cache::add($key, 0, 60);
         // Add to count
         $count = \Cache::get($key);
         if ($count > $requestsPerHour) {
             $response = \Response::make('', 429);
             $response->setContent('Rate limit exceeded, maximum of ' . $requestsPerHour . ' requests per hour has been reached.');
             return $response;
         } else {
             \Cache::increment($key);
         }
     }
 }
开发者ID:jalbertbowden,项目名称:core,代码行数:27,代码来源:DatasetController.php

示例12: testIncrement

 /**
  * testIncrement method
  *
  * @return void
  */
 public function testIncrement()
 {
     $this->skipIf(!function_exists('wincache_ucache_inc'), 'No wincache_inc() function, cannot test increment().');
     $result = Cache::write('test_increment', 5, 'wincache');
     $this->assertTrue($result);
     $result = Cache::increment('test_increment', 1, 'wincache');
     $this->assertEquals(6, $result);
     $result = Cache::read('test_increment', 'wincache');
     $this->assertEquals(6, $result);
     $result = Cache::increment('test_increment', 2, 'wincache');
     $this->assertEquals(8, $result);
     $result = Cache::read('test_increment', 'wincache');
     $this->assertEquals(8, $result);
 }
开发者ID:jgera,项目名称:orangescrum,代码行数:19,代码来源:WincacheEngineTest.php

示例13: banCall

 public static function banCall($api, $scope, $owner = 0, $accessMask = 0, $reason = null)
 {
     \Log::warning('Processing a ban request for api: ' . $api . ' scope: ' . $scope . ' owner: ' . $owner, array('src' => __CLASS__));
     // Check if we should retreive the current access mask
     if ($accessMask == 0) {
         $accessMask = \EveAccountAPIKeyInfo::where('keyID', '=', $owner)->pluck('accessMask');
     }
     // Generate a hash with which to ID this call
     $hash = BaseApi::makeCallHash($api, $scope, $owner . $accessMask);
     // Check the cache if a ban has been recorded
     if (!\Cache::has('call_ban_grace_count_' . $hash)) {
         // Record the new ban, getting the grance period from the seat config and return
         \Cache::put('call_ban_grace_count_' . $hash, 0, \Config::get('seat.ban_grace'));
         return;
     } else {
         // Check if we have reached the limit for the allowed bad calls from the config
         if (\Cache::get('call_ban_grace_count_' . $hash) < \Config::get('seat.ban_limit') - 1) {
             // Add another one to the amount of failed calls and return
             \Cache::increment('call_ban_grace_count_' . $hash);
             return;
         }
     }
     \Log::warning('Ban limit reached. Actioning ban for api: ' . $api . ' scope: ' . $scope . ' owner: ' . $owner, array('src' => __CLASS__));
     // We _should_ only get here once the ban limit has been reached
     $banned = \EveBannedCall::where('hash', '=', $hash)->first();
     if (!$banned) {
         $banned = new \EveBannedCall();
     }
     $banned->ownerID = $owner;
     $banned->api = $api;
     $banned->scope = $scope;
     $banned->accessMask = $accessMask;
     $banned->hash = $hash;
     $banned->reason = $reason;
     $banned->save();
     // We also need to keep in mind how many errors have occured so far.
     // This is mainly for the checks that are done in bootstrap()
     // allowing us to pause and not cause a IP to be banned.
     if (\Cache::has('eve_api_error_count')) {
         \Cache::increment('eve_api_error_count');
     } else {
         \Cache::put('eve_api_error_count', 1, 30);
     }
 }
开发者ID:boweiliu,项目名称:seat,代码行数:44,代码来源:BaseAPI.php

示例14: readArticleIndex

 /**
  * @return mixed
  */
 public function readArticleIndex()
 {
     if (!\Cache::has($this->getCacheArticleBeanFeedKey())) {
         \Cache::put($this->getCacheArticleBeanFeedKey(), 1, 1440);
     } else {
         if (\Cache::get($this->getCacheArticleBeanFeedKey()) < 5) {
             \Cache::increment($this->getCacheArticleBeanFeedKey());
         }
     }
     return \Cache::get($this->getCacheArticleBeanFeedKey());
 }
开发者ID:whplay,项目名称:ohmate-shop,代码行数:14,代码来源:Customer.php

示例15: testIncrement

 /**
  * testIncrement method
  *
  * @return void
  */
 public function testIncrement()
 {
     $result = Cache::write('test_increment', 5);
     $this->assertTrue($result);
     $result = Cache::increment('test_increment');
     $this->assertEquals(6, $result);
     $result = Cache::read('test_increment');
     $this->assertEquals(6, $result);
     $result = Cache::increment('test_increment', 2);
     $this->assertEquals(8, $result);
     $result = Cache::read('test_increment');
     $this->assertEquals(8, $result);
 }
开发者ID:Marcin11,项目名称:_mojePanstwo-Portal,代码行数:18,代码来源:XcacheEngineTest.php


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