コード例 #1
0
 /**
  * @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');
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 protected function doSave($id, $data, $lifeTime = false)
 {
     if (!$lifeTime) {
         return $this->cache->forever($id, $data);
     }
     return $this->cache->put($id, $data, $lifeTime);
 }
コード例 #3
0
 /**
  * setter
  *
  * @param string $key     key name
  * @param mixed  $value   the value
  * @param int    $minutes expire time
  * @return void
  */
 public function put($key, $value, $minutes = null)
 {
     if ($minutes == null) {
         $minutes = $this->minutes;
     }
     $this->cache->put($key, $value, $minutes);
 }
コード例 #4
0
ファイル: BoomCMS.php プロジェクト: boomcms/boom-core
 public function getNews()
 {
     $key = 'boomcms.news';
     return $this->cache->get($key, function () use($key) {
         $response = json_decode(@file_get_contents($this->newsUrl));
         $news = $response->news ?? [];
         $this->cache->put($key, $news, 3600);
         return $news;
     });
 }
コード例 #5
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle(Cache $cache)
 {
     $this->info('Calculating stats >>>>>');
     $expiresAt = Carbon::now()->addMinutes(10);
     $tickets = Ticket::withTrashed()->get();
     $openTickets = $tickets->filter(function ($ticket) {
         return !$ticket->trashed();
     });
     $cache->put('tickets.open', $openTickets->count(), $expiresAt);
     $cache->put('tickets.total', $tickets->count(), $expiresAt);
     $this->info('Calculation done and results are cached');
 }
コード例 #6
0
 /**
  * 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;
 }
コード例 #7
0
 /**
  * Run the given event.
  *
  * @param  \Illuminate\Contracts\Container\Container  $container
  * @return mixed
  *
  * @throws \Exception
  */
 public function run(Container $container)
 {
     if ($this->description) {
         $this->cache->put($this->mutexName(), true, 1440);
     }
     try {
         $response = $container->call($this->callback, $this->parameters);
     } finally {
         $this->removeMutex();
     }
     parent::callAfterCallbacks($container);
     return $response;
 }
コード例 #8
0
 /**
  * {@inheritdoc}
  */
 public function save(CacheItemInterface $item)
 {
     $expiresAt = $this->getExpiresAt($item);
     if (!$expiresAt) {
         try {
             $this->repository->forever($item->getKey(), serialize($item->get()));
         } catch (Exception $exception) {
             return false;
         }
         return true;
     }
     $now = new DateTimeImmutable('now', $expiresAt->getTimezone());
     $seconds = $expiresAt->getTimestamp() - $now->getTimestamp();
     $minutes = (int) floor($seconds / 60.0);
     if ($minutes <= 0) {
         $this->repository->forget($item->getKey());
         return false;
     }
     try {
         $this->repository->put($item->getKey(), serialize($item->get()), $minutes);
     } catch (Exception $exception) {
         return false;
     }
     return true;
 }
コード例 #9
0
ファイル: Rates.php プロジェクト: dannyvankooten/laravel-vat
 protected function load()
 {
     // load from cache
     if ($this->cache) {
         $map = $this->cache->get('vat-rates');
     }
     // fetch from jsonvat.com
     if (empty($map)) {
         $map = $this->fetch();
         // store in cache
         if ($this->cache) {
             $this->cache->put('vat-rates', $map, 86400);
         }
     }
     return $map;
 }
コード例 #10
0
ファイル: Cruncher.php プロジェクト: kenarkose/tracker
 /**
  * Caches count between if cacheKey is present
  *
  * @param int $count
  * @param Carbon $from
  * @param Carbon $until
  * @param string $locale
  * @param string $cacheKey
  */
 protected function cacheCountBetween($count, Carbon $from, Carbon $until, $locale, $cacheKey)
 {
     // Cache only if cacheKey is present
     if ($cacheKey && $until->timestamp < Carbon::now()->timestamp) {
         $key = $this->makeBetweenCacheKey($from, $until, $locale, $cacheKey);
         $this->cache->put($key, $count, 525600);
     }
 }
コード例 #11
0
 /**
  * Handle the command.
  *
  * @param Repository                     $cache
  * @param Request                        $request
  * @param UserAuthenticator              $authenticator
  * @param SettingRepositoryInterface     $settings
  * @param ThrottleSecurityCheckExtension $extension
  * @return bool
  */
 public function handle(Repository $cache, Request $request, UserAuthenticator $authenticator, SettingRepositoryInterface $settings, ThrottleSecurityCheckExtension $extension)
 {
     $maxAttempts = $settings->value('anomaly.extension.throttle_security_check::max_attempts', 5);
     $lockoutInterval = $settings->value('anomaly.extension.throttle_security_check::lockout_interval', 1);
     $throttleInterval = $settings->value('anomaly.extension.throttle_security_check::throttle_interval', 1);
     $attempts = $cache->get($extension->getNamespace('attempts:' . $request->ip()), 1);
     $expiration = $cache->get($extension->getNamespace('expiration:' . $request->ip()));
     if ($expiration || $attempts >= $maxAttempts) {
         $cache->put($extension->getNamespace('attempts:' . $request->ip()), $attempts + 1, $throttleInterval);
         $cache->put($extension->getNamespace('expiration:' . $request->ip()), time(), $lockoutInterval);
         $authenticator->logout();
         // Just for safe measure.
         return $this->dispatch(new MakeResponse());
     }
     $cache->put($extension->getNamespace('attempts:' . $request->ip()), $attempts + 1, $throttleInterval);
     return true;
 }
コード例 #12
0
 /**
  * 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;
 }
コード例 #13
0
ファイル: Event.php プロジェクト: jarnovanleeuwen/framework
 /**
  * Run the given event.
  *
  * @param  \Illuminate\Contracts\Container\Container  $container
  * @return void
  */
 public function run(Container $container)
 {
     if ($this->withoutOverlapping) {
         $this->cache->put($this->mutexName(), true, 1440);
     }
     if ($this->runInBackground) {
         $this->runCommandInBackground();
     } else {
         $this->runCommandInForeground($container);
     }
 }
コード例 #14
0
 public function handle(RateFetcher $source, Cache $cache)
 {
     $rates = $source->getUsdRates($this->date);
     if (!count($rates)) {
         throw new ForexException('received empty array of rates');
     }
     $cacheKey = $this->date ? $this->date->format('Y-m-d') : 'live';
     // save rates for two hours to main cache
     $cache->put(ForexService::RATE_CACHE_KEY_PREFIX . $cacheKey, $rates, 120);
     // save rates indefinitely for backup cache
     $cache->forever(ForexService::BACKUP_CACHE_KEY_PREFIX . $cacheKey, $rates);
 }
コード例 #15
0
 /**
  * Backup the field type column to cache.
  *
  * @param Blueprint $table
  */
 public function backupColumn(Blueprint $table)
 {
     // Skip if no column type.
     if (!$this->fieldType->getColumnType()) {
         return;
     }
     // Skip if the column doesn't exist.
     if (!$this->schema->hasColumn($table->getTable(), $this->fieldType->getColumnName())) {
         return;
     }
     // Back dat data up.
     $results = $this->connection->table($table->getTable())->select(['id', $this->fieldType->getColumnName()])->get();
     $this->cache->put(__CLASS__ . $this->fieldType->getColumnName(), $results, 10);
 }
コード例 #16
0
 /**
  * {@inheritdoc}
  */
 public function save(CacheItemInterface $item)
 {
     $expiresInMinutes = null;
     if ($item instanceof CacheItem) {
         $expiresInMinutes = $item->getTTL();
     }
     try {
         if (is_null($expiresInMinutes)) {
             $this->repository->forever($item->getKey(), serialize($item->get()));
         } else {
             $this->repository->put($item->getKey(), serialize($item->get()), $expiresInMinutes);
         }
     } catch (Exception $exception) {
         return false;
     }
     return true;
 }
コード例 #17
0
 /**
  * Handle an incoming request.
  *
  * @param Request     $request        Request
  * @param Closure     $next           Closure
  * @param string|null $filter_string  Filter in string format
  * @param string|null $redirect_route Named route to redirect blocked client
  *
  * @return mixed
  */
 public function handle(Request $request, Closure $next, $filter_string = null, $redirect_route = null)
 {
     $this->redirect_route = $redirect_route;
     if ($this->onRedirectPath($request)) {
         return $next($request);
     }
     $cache_key = $this->generateCacheKey($request);
     $redirect = $this->cache->get($cache_key);
     if (is_null($redirect)) {
         $this->parseFilterString($filter_string);
         $this->validateRules();
         $redirect = $this->determineRedirect();
         $this->cache->put($cache_key, $redirect, $this->getCacheTimeout());
     }
     if ($redirect) {
         $request->session()->flash('redirected', true);
         return $this->redirector->route($redirect);
     }
     return $next($request);
 }
コード例 #18
0
ファイル: Document.php プロジェクト: codexproject/core
 /**
  * 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;
 }
 /**
  * {@inheritDoc}
  */
 public function write($sessionId, $data)
 {
     return $this->cache->put($sessionId, $data, $this->minutes);
 }
コード例 #20
0
 /**
  * Save the current post in the cache
  *
  * @param \Illuminate\Contracts\Cache\Repository $cache
  * @param \Illuminate\Http\Request $request;
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function autoSave(Cache $cache, Request $request)
 {
     try {
         $hash = $this->auth_user->hash;
         $cache->put("autoSavedPost-{$hash}", $request->all(), Carbon::now()->addHours(2));
     } catch (BlogifyException $exception) {
         return response()->json([false, date('d-m-Y H:i:s')]);
     }
     return response()->json([true, date('d-m-Y H:i:s')]);
 }
コード例 #21
0
 /**
  * Cache a value
  *
  * @param string $key
  * @param mixed  $value
  * @param int    $minutes Default 1
  *
  * @return mixed
  */
 public function cachePut($key, $value, $minutes = 1)
 {
     $this->cache->put($this->cachePrefix($key), $value, $minutes);
     return $value;
 }
コード例 #22
0
 /**
  * Put the cached value.
  *
  * @param string $key
  * @param string $value
  * @param int    $lifetime
  */
 public function save($key, $value, $lifetime = 0)
 {
     $this->cache->put($key, $value, $lifetime);
 }
コード例 #23
0
 /**
  * Return the config key.
  *
  * @return string
  */
 public function configKey()
 {
     $key = md5(json_encode($this->getConfig()));
     $this->cache->put('files-field_type::' . $key, $this->getConfig(), 30);
     return $key;
 }
コード例 #24
0
ファイル: IlluminateAdapter.php プロジェクト: pierredup/Cache
 /**
  * Put the data into the storage.
  *
  * @param int    $repo
  * @param string $name
  * @param string $data
  *
  * @return void
  */
 public function put($repo, $name, $data)
 {
     $this->cache->put("analysis.{$repo}.{$name}", $data, $this->time);
 }
コード例 #25
0
 /**
  * @inheritdoc
  */
 public function replace($value)
 {
     $this->repository->put($this->cacheKey, $value, $this->cacheMinutes);
     return $this;
 }
コード例 #26
0
 public function put($key, $value, $ttl = 1440)
 {
     $this->cache->put($this->cacheKey($key), $value, $ttl);
 }
コード例 #27
0
ファイル: CachingStore.php プロジェクト: AltThree/Storage
 /**
  * Put an item into the storage.
  *
  * @param string $key
  * @param string $data
  *
  * @return void
  */
 public function put($key, $data)
 {
     $this->cache->put("store.{$key}", $data, 30);
     $this->store->put($key, $data);
 }
コード例 #28
0
 /**
  * Return the config key.
  *
  * @return string
  */
 public function key()
 {
     $this->cache->put('anomaly/relationship-field_type::' . ($key = md5(json_encode($this->getConfig()))), $this->getConfig(), 30);
     return $key;
 }
コード例 #29
0
ファイル: Cache.php プロジェクト: czim/laravel-cms-core
 /**
  * Store an item in the cache.
  *
  * @param  string        $key
  * @param  mixed         $value
  * @param  \DateTime|int $minutes
  */
 public function put($key, $value, $minutes = null)
 {
     $this->cache->put($key, $value, $minutes);
 }