/**
  * @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');
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function getItem($key)
 {
     $this->validateKey($key);
     if ($this->repository->has($key)) {
         return new CacheItem($key, unserialize($this->repository->get($key)), true);
     } else {
         return new CacheItem($key);
     }
 }
Esempio n. 3
0
 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;
     });
 }
 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. 5
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;
 }
 /**
  * @return array
  */
 public function getTeamInfo()
 {
     /**
      * @var array|null $cached
      */
     $cached = $this->cache->get(self::SLACK_TEAM_INFO_KEY);
     if (!$cached) {
         $cached = $this->refreshTeamInfo();
     }
     return $cached;
 }
 /**
  * {@inheritdoc}
  */
 public function getItem($key)
 {
     $this->validateKey($key);
     if (isset($this->deferred[$key])) {
         return clone $this->deferred[$key];
     } elseif ($this->repository->has($key)) {
         return new CacheItem($key, unserialize($this->repository->get($key)), true);
     } else {
         return new CacheItem($key);
     }
 }
 /**
  * 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;
 }
 /**
  * @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
 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;
 }
Esempio n. 11
0
 public function getBranchesToSync()
 {
     $allowedBranches = $this->setting('sync.constraints.branches');
     if (count($allowedBranches) === 0) {
         return [];
     }
     $this->fire('git.syncer.branches.start', [$allowedBranches]);
     $branchesToSync = [];
     $remote = $this->client($this->setting('remote'));
     $repo = $this->setting('repository');
     $owner = $this->setting('owner');
     $branches = $remote->getBranches($repo, $owner);
     foreach ($branches as $branch => $sha) {
         if (!in_array('*', $allowedBranches, true) and !in_array($branch, $allowedBranches, true)) {
             continue;
         }
         $cacheKey = md5($this->project->getName() . $branch);
         $cached = $this->cache->get($cacheKey, false);
         $destinationPath = Path::join($this->project->getPath(), $branch);
         if ($cached !== $sha || $cached === false || !$this->files->exists($destinationPath)) {
             $branchesToSync[] = $branch;
         }
     }
     $this->fire('git.syncer.branches.finish', [$branchesToSync]);
     return $branchesToSync;
 }
Esempio n. 12
0
 /**
  * Get the last restart timestamp, or null.
  *
  * @return int|null
  */
 protected function getTimestampRestartCommand()
 {
     if ($this->cache) {
         return $this->cache->get(self::restartID);
     }
     return null;
 }
 /**
  * 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;
 }
 /**
  * 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. 16
0
 /**
  * Get the forum tree for the index, consisting of root forums (categories), and one level of descendants.
  *
  * @param bool $checkPermissions
  *
  * @return mixed
  */
 public function getIndexTree($checkPermissions = true)
 {
     if (($forums = $this->cache->get('forums.index_tree')) == null) {
         $forums = $this->decoratedRepository->getIndexTree(false);
         $this->cache->forever('forums.index_tree', $forums);
     }
     if ($checkPermissions) {
         $forums = $this->filterUnviewableForums($forums);
     }
     return $forums;
 }
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $this->pluginEnabled();
     $queue = $this->option('queue');
     $connection = $this->argument('connection');
     $flag = $this->cache->get($this->flagHelper->getFlagName($connection, $queue), 0);
     if ($this->flagIsDown($flag)) {
         $killedWorkers = $this->kuduHelper->killQueueWorkers($connection, $queue);
         if ($killedWorkers === 0) {
             throw new QueueProcessesNotKilledException('The "' . $this->flagHelper->getQueueName($queue) . '" queue on connection "' . $this->flagHelper->getConnectionName($connection) . '" is unresponsive, but the process could not be terminated.');
         }
         $infoString = 'The "' . $this->flagHelper->getQueueName($queue) . '" queue on connection "' . $this->flagHelper->getConnectionName($connection) . '" was unresponsive. ' . $killedWorkers . ' process';
         if ($killedWorkers > 1) {
             $infoString .= 'es were';
         } else {
             $infoString .= ' was';
         }
         $infoString .= ' terminated.';
         throw new UnresponsiveQueueWorkerException($infoString);
     }
 }
Esempio n. 18
0
 /**
  * Execute the console command.
  *
  * @param Repository $cache
  *
  * @return mixed
  */
 public function handle(Repository $cache)
 {
     $iterations_count = $this->argument('iterations') ?: 1;
     /** @var BaseBot $bot */
     $bot = app('Bot');
     while ($iterations_count--) {
         $updatesChunk = $bot->getTelegram()->getUpdates($cache->get(self::CACHE_KEY) + 1, null, 3);
         foreach ($updatesChunk as $update) {
             $bot->handle($update);
             $cache->forever(self::CACHE_KEY, $update->update_id);
         }
     }
 }
Esempio n. 19
0
 private function verify($key)
 {
     if (!isset($key) || !is_string($key)) {
         throw new InvalidArgumentException('Invalid Option Key!');
     }
     $group = $this->config->get('option.group');
     if (empty($group)) {
         throw new InvalidArgumentException('default prefix can not be empty');
     }
     if (!str_is('*.*', $key)) {
         $key = sprintf('%s.%s', $group, $key);
     }
     return $key;
 }
 /**
  * Handle the filters.
  *
  * @param FileTableBuilder          $builder
  * @param FolderRepositoryInterface $folders
  * @param Repository                $cache
  * @param Request                   $request
  */
 public function handle(FileTableBuilder $builder, FolderRepositoryInterface $folders, Repository $cache, Request $request)
 {
     $allowed = [];
     $config = $cache->get('files-field_type::' . $request->route('key'), []);
     foreach (array_get($config, 'folders', []) as $identifier) {
         /* @var FolderInterface $folder */
         if ($folder = $this->dispatch(new GetFolder($identifier))) {
             $allowed[$folder->getId()] = $folder->getName();
         }
     }
     if (!$allowed) {
         $allowed = $folders->all()->pluck('name', 'id')->all();
     }
     $builder->setFolders($allowed)->setFilters(['search' => ['columns' => ['name', 'keywords', 'mime_type']], 'folder' => ['exact' => true, 'filter' => 'select', 'options' => $allowed, 'enabled' => count($allowed) !== 1]]);
 }
Esempio n. 21
0
 /**
  * Return a list of folders to choose from.
  *
  * @param FolderRepositoryInterface $folders
  * @param Repository                $cache
  * @param Request                   $request
  * @return \Illuminate\View\View
  */
 public function choose(FolderRepositoryInterface $folders, Repository $cache, Request $request)
 {
     $allowed = [];
     $config = $cache->get('file-field_type::' . $request->route('key'), []);
     foreach (array_get($config, 'folders', []) as $identifier) {
         /* @var FolderInterface $folder */
         if ($folder = $this->dispatch(new GetFolder($identifier))) {
             $allowed[] = $folder;
         }
     }
     if (!$allowed) {
         $allowed = $folders->all();
     }
     return $this->view->make('anomaly.field_type.file::choose', ['folders' => $allowed]);
 }
Esempio n. 22
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);
 }
 /**
  * Restore the field type column to cache.
  *
  * @param Blueprint $table
  */
 public function restoreColumn(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;
     }
     // Translatable or no?
     $translatable = ends_with($table->getTable(), '_translations');
     // Restore the data.
     $results = $this->cache->get(__CLASS__ . $this->fieldType->getColumnName());
     foreach ($results as $result) {
         $result = (array) $result;
         $this->connection->table($table->getTable())->where($translatable ? 'entry_id' : 'id', array_pull($result, 'id'))->update($result);
     }
     $this->cache->forget(__CLASS__ . $this->fieldType->getColumnName());
 }
 /**
  * {@inheritDoc}
  */
 public function boot(ViewFactory $viewFactory, CacheRepository $cache)
 {
     // Define views path
     $this->loadViewsFrom(__DIR__ . '/../resources/views', 'queue-monitor');
     // Composer for the status views
     $composer = function ($view) use($cache) {
         $queues = [];
         foreach ($cache->get(QueueMonitor::QUEUES_CACHE_KEY, []) as $queueName) {
             $status = QueueStatus::get($queueName);
             if (!$status) {
                 $status = new QueueStatus($queueName, QueueStatus::ERROR, false);
                 $status->setMessage("Status not found in cache; is a cron job set up and running?");
             }
             $queues[$queueName] = $status;
         }
         $view->withQueues($queues);
     };
     $viewFactory->composer('queue-monitor::status', $composer);
     $viewFactory->composer('queue-monitor::status-json', $composer);
 }
Esempio n. 25
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. 26
0
 public function getBranchesToSync()
 {
     $allowedBranches = $this->setting('sync.sync.branches');
     if (count($allowedBranches) === 0) {
         return [];
     }
     $branchesToSync = [];
     $branches = $this->github->repositories()->branches($this->setting('owner'), $this->setting('repository'));
     foreach ($branches as $branch) {
         $branchName = $branch['name'];
         if (!in_array('*', $allowedBranches, true) and !in_array($branchName, $allowedBranches, true)) {
             continue;
         }
         $sha = $branch['commit']['sha'];
         $cacheKey = md5($this->project->getName() . $branchName);
         $branch = $this->cache->get($cacheKey, false);
         $destinationPath = Path::join($this->project->getPath(), $branchName);
         if ($branch !== $sha or $branch === false or !$this->files->exists($destinationPath)) {
             $branchesToSync[] = $branchName;
         }
     }
     return $branchesToSync;
 }
Esempio n. 27
0
 /**
  * Get the last queue restart timestamp, or null.
  *
  * @return int|null
  */
 protected function getTimestampOfLastQueueRestart()
 {
     if ($this->cache) {
         return $this->cache->get('illuminate:queue:restart');
     }
 }
Esempio n. 28
0
 /**
  * Gets the cached count if there is any
  *
  * @param Carbon $from
  * @param Carbon $until
  * @param string $locale
  * @param string $cacheKey
  * @return int|null
  */
 protected function getCachedCountBetween(Carbon $from, Carbon $until, $locale, $cacheKey)
 {
     $key = $this->makeBetweenCacheKey($from, $until, $locale, $cacheKey);
     return $this->cache->get($key);
 }
Esempio n. 29
0
 /**
  * Get the number of seconds until the "key" is accessible again.
  *
  * @param  string  $key
  * @return int
  */
 public function availableIn($key)
 {
     return $this->cache->get($key . ':lockout') - time();
 }
 /**
  * {@inheritDoc}
  */
 public function read($sessionId)
 {
     return $this->cache->get($sessionId, '');
 }