Esempio n. 1
0
 public function update($id, array $attribute)
 {
     if ($this->model->update($id, $attribute)) {
         $this->cache->forget($this->getKey('all'));
         $this->cache->forget($this->getKey('id-' . $id));
     }
 }
 /**
  * Returns the current cache instance
  *
  * @param  array $tags
  *
  * @return Cache
  */
 protected function getCache(array $tags)
 {
     if ($this->cache instanceof TaggableStore) {
         return $this->cache->tags(array_merge(['russian'], $tags));
     }
     return $this->cache;
 }
Esempio n. 3
0
 /**
  * Return the cache instance with tags attached.
  *
  * @return \Illuminate\Contracts\Cache\Repository|\Illuminate\Contracts\Cache\Store
  */
 protected function cache()
 {
     if (!method_exists($this->cache, 'tags')) {
         return $this->cache;
     }
     return $this->cache->tags($this->tag);
 }
 /**
  * Get the decoded contents from the main composer.json file
  * @return object
  */
 private function getComposerFile()
 {
     $composerFile = $this->cache->remember('app.version', 1440, function () {
         return $this->filesystem->get('composer.json');
     });
     return json_decode($composerFile);
 }
 /**
  * @param $name
  *
  * @return Sidebar
  */
 public function resolve($name)
 {
     $duration = $this->config->get('sidebar.cache.duration');
     return $this->cache->remember(CacheKey::get($name), $duration, function () use($name) {
         return $this->resolver->resolve($name);
     });
 }
 /**
  * @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');
 }
 /**
  * @param Repository $repository
  *
  * @throws CacheTagsNotSupported
  * @return bool
  */
 public function isSatisfiedBy(Repository $repository)
 {
     if (!method_exists($repository->getStore(), 'tags')) {
         throw new CacheTagsNotSupported('Cache tags are necessary to use this kind of caching. Consider using a different caching method');
     }
     return true;
 }
Esempio n. 8
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle(Cache $cache)
 {
     $ips = $this->fetchExitNodeIPs()->map(function ($ip) use($cache) {
         $cache->tags(config('torinfo.caching.tags'))->put($ip, true, config('torinfo.caching.expiry'));
         return $ip;
     });
 }
 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')]]);
 }
Esempio n. 10
0
 /**
  *
  */
 public function __call($method, $params)
 {
     if (!method_exists($this->repository, $method)) {
         throw new RepositoryException("Method {$method} not found on repository");
     }
     if ($this->skipCache === true || config('laravel-database.cache') === false) {
         return call_user_func_array(array($this->repository, $method), $params);
     } else {
         if (empty($this->key)) {
             $this->cacheKey($this->generateKey($method, $params));
         }
         $key = $this->key;
         unset($this->key);
         if ($this->refreshCache) {
             $this->cache->forget($key);
             $this->refreshCache = false;
         }
         if (empty($this->lifetime)) {
             $this->cacheLifetime($this->repository->getModel()->cacheLifetime());
         }
         $lifetime = $this->lifetime;
         unset($this->lifetime);
         return $this->cache->remember($key, $lifetime, function () use($method, $params) {
             return call_user_func_array(array($this->repository, $method), $params);
         });
     }
 }
Esempio n. 11
0
 /**
  * Show the getting started screen to the user.
  *
  * @param MarkdownParser $markdown
  * @param Cache          $cache
  * @param Filesystem     $file
  *
  * @return Response
  */
 public function gettingStarted(MarkdownParser $markdown, Cache $cache, Filesystem $file)
 {
     $gettingStarted = $cache->remember('getting-started', 5, function () use($markdown, $file) {
         $gettingStarted = $file->get(base_path('resources/getting-started/readme.md'));
         return $markdown->parse($gettingStarted);
     });
     return view('getting-started')->with(compact('gettingStarted'));
 }
Esempio n. 12
0
File: Trust.php Progetto: znck/trust
 /**
  * @param bool $forget
  *
  * @return \Illuminate\Database\Eloquent\Collection|Role[]|null
  */
 public function roles(bool $forget = false)
 {
     if ($forget === true) {
         return $this->cache->forget(self::ROLE_KEY);
     }
     return $this->cache->rememberForever(self::ROLE_KEY, function () {
         return app(Role::class)->with('permissions')->get();
     });
 }
Esempio n. 13
0
 /**
  * Execute the query as a "select" statement.
  *
  * @param  array $columns
  * @return array|static[]
  */
 public function get($columns = ['*'])
 {
     $cacheKey = $this->generateCacheKey();
     if (null === ($results = $this->cache->tags($this->cacheTag)->get($cacheKey))) {
         $results = parent::get($columns);
         $this->cache->tags($this->cacheTag)->forever($cacheKey, $results);
     }
     return $results;
 }
Esempio n. 14
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. 16
0
 /**
  * Get the given documentation page.
  *
  * @param  string  $version
  * @param  string  $page
  * @return string
  */
 public function get($version, $page)
 {
     return $this->cache->remember('docs.' . $version . '.' . $page, 5, function () use($version, $page) {
         $path = base_path('resources/docs/' . $page . '.md');
         if ($this->files->exists($path)) {
             return $this->replaceLinks($version, markdown($this->files->get($path)));
         }
         return null;
     });
 }
Esempio n. 17
0
 /**
  * Query the Google Analytics Service with given parameters.
  *
  * @param string    $viewId
  * @param \DateTime $startDate
  * @param \DateTime $endDate
  * @param string    $metrics
  * @param array     $others
  *
  * @return array|null
  */
 public function performQuery(string $viewId, DateTime $startDate, DateTime $endDate, string $metrics, array $others = [])
 {
     $cacheName = $this->determineCacheName(func_get_args());
     if ($this->cacheLifeTimeInMinutes == 0) {
         $this->cache->forget($cacheName);
     }
     return $this->cache->remember($cacheName, $this->cacheLifeTimeInMinutes, function () use($viewId, $startDate, $endDate, $metrics, $others) {
         return $this->service->data_ga->get("ga:{$viewId}", $startDate->format('Y-m-d'), $endDate->format('Y-m-d'), $metrics, $others);
     });
 }
 /**
  * @param $name
  *
  * @return Sidebar
  */
 public function resolve($name)
 {
     if ((new SupportsCacheTags())->isSatisfiedBy($this->cache)) {
         $userId = $this->guard->check() ? $this->guard->user()->getAuthIdentifier() : null;
         $duration = $this->config->get('sidebar.cache.duration');
         return $this->cache->tags(CacheKey::get($name))->remember(CacheKey::get($name, $userId), $duration, function () use($name) {
             return $this->resolver->resolve($name);
         });
     }
 }
Esempio n. 19
0
 /**
  * @param $name
  * @param $arguments
  * @return mixed
  */
 public function __call($name, $arguments)
 {
     /*
      * simple strategy: for any database altering method we do the following:
      * - call the parent method
      * - bust the cache
      */
     $result = call_user_func_array([$this->menu, $name], $arguments);
     $this->cache->forget('menus');
     return $result;
 }
Esempio n. 20
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. 21
0
 /**
  * Get the form.
  *
  * @return FormPresenter
  */
 public function get()
 {
     $this->fire('ready', ['criteria' => $this]);
     array_set($this->parameters, 'key', md5(json_encode($this->parameters)));
     array_set($this->parameters, 'options.url', array_get($this->parameters, 'options.url', $this->builder->getOption('url', 'form/handle/' . array_get($this->parameters, 'key'))));
     $this->cache->remember('form::' . array_get($this->parameters, 'key'), 30, function () {
         return $this->parameters;
     });
     $this->hydrator->hydrate($this->builder, $this->parameters);
     return (new Decorator())->decorate($this->builder->make()->getForm());
 }
Esempio n. 22
0
 /**
  * Get a cached paginated list of all users
  * 	
  *	@param int $howMany
  * 	
  *	@param string $byFirstname
  *
  *	@return mixed
  */
 public function getPaginated($howMany = 10, $byFirstname = null)
 {
     $this->howMany = $howMany;
     $this->byFirstname = $byFirstname;
     if (!$this->byFirstname) {
         return $this->cache->remember('users.all', 20, function () {
         });
     } else {
         return $this->repository->getPaginated($this->howMany, $this->byFirstname);
     }
 }
Esempio n. 23
0
 /**
  * Returns the latest release.
  *
  * @return string
  */
 public function latest()
 {
     $release = $this->cache->remember('release.latest', 720, function () {
         $headers = ['Accept' => 'application/vnd.github.v3+json', 'User-Agent' => defined('CACHET_VERSION') ? 'cachet/' . constant('CACHET_VERSION') : 'cachet'];
         if ($this->token) {
             $headers['OAUTH-TOKEN'] = $this->token;
         }
         return json_decode((new Client())->get($this->url, ['headers' => $headers])->getBody(), true);
     });
     return ['tag_name' => $release['tag_name'], 'prelease' => $release['prerelease'], 'draft' => $release['draft']];
 }
Esempio n. 24
0
 /**
  * Returns the latest credits.
  *
  * @return array|null
  */
 public function latest()
 {
     $result = $this->cache->remember('credits', 2880, function () {
         try {
             return json_decode((new Client())->get($this->url, ['headers' => ['Accept' => 'application/json', 'User-Agent' => defined('CACHET_VERSION') ? 'cachet/' . constant('CACHET_VERSION') : 'cachet']])->getBody(), true);
         } catch (Exception $e) {
             return self::FAILED;
         }
     });
     return $result === self::FAILED ? null : $result;
 }
 /**
  * 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');
 }
Esempio n. 26
0
 public function handle()
 {
     try {
         $configs = $this->config->get('acl');
         $this->permissionManager->deleteAllPermissions();
         $this->cache->forget($configs['acl.permission_cache_key']);
         $this->cache->tags($configs['acl.user_permissions_cache_key'])->flush();
         $this->info('All permissions are deleted from database and cache');
     } catch (\Exception $e) {
         $this->error($e->getMessage());
     }
 }
Esempio n. 27
0
 /**
  * Returns the latest GitHub release.
  *
  * @return string
  */
 public function latest()
 {
     $release = $this->cache->remember('version', 720, function () {
         $headers = ['Accept' => 'application/vnd.github.v3+json'];
         // We can re-use the Emoji token here, if we have it.
         if ($token = $this->config->get('services.github.token')) {
             $headers['OAUTH-TOKEN'] = $token;
         }
         return json_decode((new Client())->get('https://api.github.com/repos/cachethq/cachet/releases/latest', ['headers' => $headers])->getBody(), true);
     });
     return $release['tag_name'];
 }
 /**
  * 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;
 }
 /**
  * Get the given documentation page.
  *
  * @param  string $version
  * @param  string $page
  *
  * @return string
  */
 public function get($version, $page)
 {
     return $this->cache->remember('docs.' . $version . '.' . $page, $this->cacheTime, function () use($version, $page) {
         $path = $this->fullPagePath($version, $page);
         if ($this->files->exists($path)) {
             $content = $this->replaceLinks($version, markdown($this->files->get($path)));
             $title = $content ? $this->getDocTitleByContent($content) : null;
             return compact('content', 'title');
         }
         return null;
     });
 }
 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);
 }