public function stats(Cache $cache)
 {
     if (!$cache->has('tickets.total') && !$cache->has('tickets.open')) {
         return $this->responseNoteFound('No stats found');
     }
     return $this->respond(['tickets' => ['open' => $cache->get('tickets.open'), 'total' => $cache->get('tickets.total')]]);
 }
 /**
  * @return string Access token
  */
 public function authenticate()
 {
     if (!$this->repository->has('brightcove.bearer')) {
         $this->repository->put('brightcove.bearer', $this->brightcove->authenticate(), $this->duration);
     }
     return $this->repository->get('brightcove.bearer');
 }
 public function check($value)
 {
     $result = false;
     if ($this->store->has('captcha')) {
         $captchaStore = $this->store->get('captcha');
         $result = $captchaStore->check($value);
         $this->store->forever('captcha', $captchaStore);
     }
     return $result;
 }
Esempio n. 4
0
 /**
  * Get the dataset collection
  *
  * @return \Illuminate\Support\Collection
  */
 public function all()
 {
     $cacheKey = 'dataset' . (new ReflectionClass($this))->getShortName();
     if ($this->cache->has($cacheKey)) {
         return $this->cache->get($cacheKey);
     }
     $dataset = $this->cache->rememberForever($cacheKey, function () {
         return $this->getDataset();
     });
     return $dataset;
 }
Esempio n. 5
0
 /**
  * Determine if the given key has been "accessed" too many times.
  *
  * @param  string  $key
  * @param  int  $maxAttempts
  * @param  int  $decayMinutes
  * @return bool
  */
 public function tooManyAttempts($key, $maxAttempts, $decayMinutes = 1)
 {
     $lockedOut = $this->cache->has($key . ':lockout');
     if ($this->attempts($key) > $maxAttempts || $lockedOut) {
         if (!$lockedOut) {
             $this->cache->add($key . ':lockout', time() + $decayMinutes * 60, $decayMinutes);
         }
         return true;
     }
     return false;
 }
Esempio n. 6
0
 /**
  * Determine if the given key has been "accessed" too many times.
  *
  * @param  string  $key
  * @param  int  $maxAttempts
  * @param  float|int  $decayMinutes
  * @return bool
  */
 public function tooManyAttempts($key, $maxAttempts, $decayMinutes = 1)
 {
     if ($this->cache->has($key . ':lockout')) {
         return true;
     }
     if ($this->attempts($key) > $maxAttempts) {
         $this->cache->add($key . ':lockout', time() + $decayMinutes * 60, $decayMinutes);
         $this->resetAttempts($key);
         return true;
     }
     return false;
 }
 /**
  * Query the Google Analytics Real Time Reporting Service with given parameters.
  *
  * @param int    $id
  * @param string $metrics
  * @param array  $others
  *
  * @return mixed
  */
 public function performRealTimeQuery($id, $metrics, array $others = [])
 {
     $realTimeCacheName = $this->determineRealTimeCacheName(func_get_args());
     if ($this->useRealTimeCache() && $this->cache->has($realTimeCacheName)) {
         return $this->cache->get($realTimeCacheName);
     }
     $googleAnswer = $this->service->data_realtime->get($id, $metrics, $others);
     if ($this->useRealTimeCache()) {
         $this->cache->put($realTimeCacheName, $googleAnswer, Carbon::now()->addSeconds($this->realTimeCacheLifeTimeInSeconds));
     }
     return $googleAnswer;
 }
 /**
  * {@inheritdoc}
  */
 public function hasItem($key)
 {
     $this->validateKey($key);
     if (isset($this->deferred[$key])) {
         $item = $this->deferred[$key];
         $expiresAt = $this->getExpiresAt($item);
         if (!$expiresAt) {
             return true;
         }
         return $expiresAt > new DateTimeImmutable();
     }
     return $this->repository->has($key);
 }
 /**
  * @param mixed $identifier
  * @return \Illuminate\Contracts\Auth\Authenticatable|null
  */
 public function retrieveById($identifier)
 {
     $cacheKey = "user:{$identifier}";
     if ($this->cache->has($cacheKey)) {
         return $this->cache->get($cacheKey);
     }
     $result = $this->createModel()->newQuery()->find($identifier);
     if (is_null($result)) {
         return null;
     }
     $this->cache->add($cacheKey, $result, 120);
     return $result;
 }
Esempio n. 10
0
 /**
  * Do not allow the event to overlap each other.
  *
  * @return $this
  */
 public function withoutOverlapping()
 {
     $this->withoutOverlapping = true;
     return $this->skip(function () {
         return $this->cache->has($this->mutexName());
     });
 }
 /**
  * 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);
 }
 /**
  * Get Full Insights From Watson API.
  *
  * @throws \FindBrok\WatsonBridge\Exceptions\WatsonBridgeException
  *
  * @return \Illuminate\Support\Collection
  */
 public function getProfileFromWatson()
 {
     //We have the request in cache and cache is on
     if ($this->cacheIsOn() && $this->cache->has($this->getContainer()->getCacheKey())) {
         //Return results from cache
         return $this->cache->get($this->getContainer()->getCacheKey());
     }
     //Cross the bridge
     $response = $this->makeBridge()->post('v2/profile', $this->getContainer()->getContentsForRequest());
     //Decode profile
     $profile = collect(json_decode($response->getBody()->getContents(), true));
     //Cache results if cache is on
     if ($this->cacheIsOn()) {
         $this->cache->put($this->getContainer()->getCacheKey(), $profile, $this->cacheLifetime());
     }
     //Return profile
     return $profile;
 }
 /**
  * Authコンポーネントのuser()メソッドなどを利用した場合に実行されるメソッドです
  * デフォルトの場合、user()メソッドコール時に都度SQLが発行されますので、cacheを利用します。
  * ユーザー情報更新時などにcacheを再生成するように実装します。
  *
  * @param  mixed $identifier
  *
  * @return \Illuminate\Contracts\Auth\Authenticatable|null
  */
 public function retrieveById($identifier)
 {
     /**
      * user:$identifier(user_id) としてキャッシュを検索し、
      * 見つからない場合は作成してデータベースから取得したデータを保持します
      * 以降はデータベースへアクセスしません
      */
     $cacheKey = "user:{$identifier}";
     if ($this->cache->has($cacheKey)) {
         return $this->cache->get($cacheKey);
     }
     $result = $this->createModel()->newQuery()->find($identifier);
     if (is_null($result)) {
         return null;
     }
     $this->cache->add($cacheKey, $result, 120);
     return $result;
 }
Esempio n. 14
0
 /**
  * Do not allow the event to overlap each other.
  *
  * @return $this
  *
  * @throws \LogicException
  */
 public function withoutOverlapping()
 {
     if (!isset($this->description)) {
         throw new LogicException("A scheduled event name is required to prevent overlapping. Use the 'name' method before 'withoutOverlapping'.");
     }
     return $this->skip(function () {
         return $this->cache->has($this->mutexName());
     });
 }
Esempio n. 15
0
 /**
  * Render the document.
  *
  * This will run all document:render hooks and then return the
  * output. Should be called within a view.
  *
  * @return string
  */
 public function render()
 {
     if ($this->rendered) {
         return $this->content;
     }
     // todo implement this. if changes are made that influence the attributes (ex, the project config), the cache should drop.
     // this is a example of how to create a unique hash for it. not sure if it would work out
     //        $attributesChanged = md5(collect(array_dot($this->attributes))->values()->transform(function ($val) {
     //            return md5((string)$val);
     //        })->implode('.'));
     $this->codex->dev->benchmark('document');
     $this->hookPoint('document:render');
     if ($this->shouldCache()) {
         $minutes = $this->getCodex()->config('document.cache.minutes', null);
         if ($minutes === null) {
             $lastModified = (int) $this->cache->rememberForever($this->getCacheKey(':last_modified'), function () {
                 return 0;
             });
         } else {
             $lastModified = (int) $this->cache->remember($this->getCacheKey(':last_modified'), $minutes, function () {
                 return 0;
             });
         }
         if ($this->lastModified !== $lastModified || $this->cache->has($this->getCacheKey()) === false) {
             $this->runProcessors();
             $this->cache->put($this->getCacheKey(':last_modified'), $this->lastModified, $minutes);
             $this->cache->put($this->getCacheKey(':content'), $this->content, $minutes);
         } else {
             $this->content = $this->cache->get($this->getCacheKey(':content'));
         }
     } else {
         $this->runProcessors();
     }
     $this->rendered = true;
     $this->hookPoint('document:rendered');
     $this->codex->dev->addMessage($this->toArray());
     $this->codex->dev->stopBenchmark(true);
     return $this->content;
 }
Esempio n. 16
0
 /**
  * {@inheritdoc}
  */
 public function hasItem($key)
 {
     $this->validateKey($key);
     return $this->repository->has($key);
 }
Esempio n. 17
0
 /**
  * Check if the given key exists in the cache.
  *
  * @param mixed $key
  */
 public function has($key)
 {
     $key = $this->normalizeCacheKey($key);
     return $this->cache->has($key);
 }
 /**
  * Tests if an entry exists in the cache.
  *
  * @param string $id The cache id of the entry to check for.
  *
  * @return bool TRUE if a cache entry exists for the given cache id, FALSE otherwise.
  */
 protected function doContains($id)
 {
     return (bool) $this->cache->has($id);
 }
Esempio n. 19
0
 /**
  * Determine whether the user has been locked out.
  *
  * @author	Andrea Marco Sartori
  * @return	boolean
  */
 public function lockedOut()
 {
     return $this->cache->has($this->lockOutKey);
 }
Esempio n. 20
0
 /**
  * Determine if an item exists in the cache.
  *
  * @param  string $key
  * @return bool
  */
 public function has($key)
 {
     return $this->cache->has($key);
 }