本文整理汇总了PHP中Illuminate\Contracts\Cache\Repository::increment方法的典型用法代码示例。如果您正苦于以下问题:PHP Repository::increment方法的具体用法?PHP Repository::increment怎么用?PHP Repository::increment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Contracts\Cache\Repository
的用法示例。
在下文中一共展示了Repository::increment方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Source: http://fideloper.com/laravel-http-middleware.
*/
public function handle($request, Closure $next)
{
$limit = $this->config->get('api.ratelimit.requests');
$time = $this->config->get('api.ratelimit.time');
// Rate limit by IP address
$key = sprintf('api:%s', $request->get('key'));
// Add if doesn't exist
$this->cache->add($key, 0, $time);
// Add to count
$count = $this->cache->increment($key);
if ($count > $limit) {
throw new TooManyRequestsHttpException($time * 60, 'Rate limit exceed.');
}
return $next($request);
}
示例2: addHit
/**
* Increment the hit counter for the cache key.
*
* @param string $key
*
* @return bool
*/
public function addHit($key)
{
if (!$this->cache->has($this->getKey($key))) {
return $this->cache->add($this->getKey($key), 1, 1);
}
return $this->cache->increment($this->getKey($key), 1);
}
开发者ID:bexarcreative,项目名称:using-rate-limiting-on-method-calls-with-laravel,代码行数:14,代码来源:RateLimiter.php
示例3: hit
/**
* Increment the counter for a given key for a given decay time.
*
* @param string $key
* @param int $decayMinutes
* @return int
*/
public function hit($key, $decayMinutes = 1)
{
$this->cache->add($key, 1, $decayMinutes);
return (int) $this->cache->increment($key);
}
示例4: incrementAttempts
/**
* Increment the number of failed attempts.
*
* @author Andrea Marco Sartori
* @return void
*/
public function incrementAttempts()
{
$this->cache->add($this->key, 0, $this->getExpiry());
$this->cache->increment($this->key);
}