예제 #1
20
 /**
  *
  */
 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);
         });
     }
 }
 /**
  * @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);
     });
 }
 /**
  * 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);
 }
예제 #4
0
 /**
  * Get the collaborators for a repo.
  *
  * @param \StyleCI\StyleCI\Models\Repo $repo
  *
  * @return int[]
  */
 public function get(Repo $repo)
 {
     // cache the collaborator info from github for 12 hours
     return $this->cache->remember("{$repo->id}collaborators", 720, function () use($repo) {
         return $this->fetchFromGitHub($repo->user, $repo->name);
     });
 }
예제 #5
0
 /**
  * Get an item from the storage.
  *
  * @param string $key
  *
  * @return string|null
  */
 public function get($key)
 {
     $data = $this->cache->remember("store.{$key}", 30, function () use($key) {
         return $this->store->get($key);
     });
     if ($data) {
         return $data;
     }
 }
예제 #6
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);
     });
 }
예제 #7
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;
     });
 }
예제 #8
0
파일: Releases.php 프로젝트: aksalj/Cachet
 /**
  * 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']];
 }
예제 #9
0
파일: Credits.php 프로젝트: aksalj/Cachet
 /**
  * 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;
 }
예제 #10
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);
     }
 }
예제 #11
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());
 }
예제 #12
0
파일: Feed.php 프로젝트: aksalj/Cachet
 /**
  * Returns the latest entries.
  *
  * @return array|null
  */
 public function latest()
 {
     $result = $this->cache->remember('feeds', 720, function () {
         try {
             $xml = simplexml_load_string((new Client())->get($this->url, ['headers' => ['Accept' => 'application/rss+xml', 'User-Agent' => defined('CACHET_VERSION') ? 'cachet/' . constant('CACHET_VERSION') : 'cachet']])->getBody()->getContents(), null, LIBXML_NOCDATA);
             return json_decode(json_encode($xml));
         } catch (Exception $e) {
             return self::FAILED;
         }
     });
     return $result === self::FAILED ? null : $result;
 }
 /**
  * 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;
     });
 }
예제 #14
0
 /**
  * Get a user's repos.
  *
  * @param \StyleCI\StyleCI\Models\User $user
  * @param bool                         $admin
  *
  * @return array
  */
 public function get(User $user, $admin = false)
 {
     // cache the repo info from github for 12 hours
     $list = $this->cache->remember($user->id . 'repos', 720, function () use($user) {
         return $this->fetchFromGitHub($user);
     });
     foreach (Repo::whereIn('id', array_keys($list))->get() as $repo) {
         $list[$repo->id]['enabled'] = true;
         $this->syncWithDatabase($repo, $list[$repo->id]);
     }
     return $list;
 }
예제 #15
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'];
 }
예제 #16
0
 /**
  * Get the given documentation page.
  *
  * @param  string  $version
  * @param  string  $page
  * @return string
  */
 public function get($version, $page)
 {
     // If the enviroment is local forget the cache
     if (app()->environment() == 'local') {
         $this->cache->forget('docs.' . $version . '.' . $page);
     }
     return $this->cache->remember('docs.' . $version . '.' . $page, 5, function () use($version, $page) {
         $path = base_path('resources/docs/' . $version . '/' . $page . '.md');
         if ($this->files->exists($path)) {
             return $this->replaceLinks($version, markdown($this->files->get($path)));
         }
         return null;
     });
 }
예제 #17
0
 /**
  * Build the builder.
  *
  * @return FormBuilder
  */
 public function build()
 {
     /*
      * Hide breadcrumbs by default.
      */
     array_set($this->parameters, 'options.breadcrumb', array_get($this->parameters, 'options.breadcrumb', false));
     /*
      * Cache and hash!
      */
     array_set($this->parameters, 'key', md5(json_encode($this->parameters)));
     /*
      * Set the forms URL after obtaining
      * our parameter hash for the form.
      */
     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;
     });
     if (is_array(array_get($this->parameters, 'options'))) {
         foreach (array_pull($this->parameters, 'options') as $key => $value) {
             $this->builder->setOption($key, $value);
         }
     }
     return $this->hydrator->hydrate($this->builder, $this->parameters);
 }
예제 #18
0
 /**
  * Cache a view. If minutes are null, the view is cached forever.
  *
  * @param array        $data
  * @param string       $view
  * @param array        $mergeData
  * @param int          $minutes
  * @param string       $key
  * @param string|array $tag
  *
  * @return string
  */
 public function cache($data, $view, $mergeData = null, $minutes = null, $key = null, $tag = null)
 {
     if (!$this->enabled) {
         return call_user_func($this->renderView($view, $data, $mergeData));
     }
     $viewKey = $this->getCacheKeyForView($view, $key);
     $mergeData = $mergeData ?: [];
     $tags = [$this->cacheKey];
     if ($tag) {
         if (!is_array($tag)) {
             $tag = [$tag];
         }
         $tags = array_merge($tags, $tag);
     }
     if ($this->cacheIsTaggable && $minutes === null) {
         return $this->cache->tags($tags)->rememberForever($viewKey, $this->renderView($view, $data, $mergeData));
     }
     if ($this->cacheIsTaggable) {
         return $this->cache->tags($tags)->remember($viewKey, $minutes, $this->renderView($view, $data, $mergeData));
     }
     if ($minutes === null) {
         return $this->cache->rememberForever($viewKey, $this->renderView($view, $data, $mergeData));
     }
     return $this->cache->remember($viewKey, $minutes, $this->renderView($view, $data, $mergeData));
 }
예제 #19
0
 /**
  * Get the raw branch list.
  *
  * @param \StyleCI\StyleCI\Models\Repo $repo
  *
  * @return array
  */
 protected function getRaw(Repo $repo)
 {
     // cache the branch info from github for 12 hours
     return $this->cache->remember($repo->id . 'branches', 720, function () use($repo) {
         return $this->fetchFromGitHub($repo);
     });
 }
예제 #20
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'));
 }
 /**
  * Retrieve a model object by its reference value, if it has one
  *
  * @param $reference
  * @return null
  */
 public function byReference($reference)
 {
     if ($this->model->isFillable('ref')) {
         $key = $this->resourceName . '.ref.' . $reference;
         return $this->cache->remember($key, 10, function () use($reference) {
             return $this->model->where('ref', $reference)->first();
         });
     } else {
         return null;
     }
 }
 /**
  * Handle the widget data.
  */
 public function handle(\SimplePie $rss, Repository $cache, ConfigurationRepositoryInterface $configuration)
 {
     $items = $cache->remember(__METHOD__, 30, function () use($rss, $configuration) {
         // Let Laravel cache everything.
         $rss->enable_cache(false);
         // Hard-code this for now.
         $rss->set_feed_url($configuration->value('anomaly.extension.xml_feed_widget::url', $this->widget->getId(), 'http://www.pyrocms.com/posts/rss.xml'));
         // Make the request.
         $rss->init();
         return $rss->get_items(0, 5);
     });
     // Load the items to the widget's view data.
     $this->widget->addData('items', $items);
 }
예제 #23
0
 /**
  * Get the latest release from Github.
  *
  * @return false|string
  */
 public function latest()
 {
     $cache_for = self::CACHE_TIME_IN_HOURS * 60;
     $release = $this->cache->remember('latest_version', $cache_for, function () {
         $request = Request::get($this->github_url)->timeoutIn(5)->expectsJson()->withAccept('application/vnd.github.v3+json');
         if (config('deployer.github_oauth_token')) {
             $request->withAuthorization('token ' . config('deployer.github_oauth_token'));
         }
         try {
             $response = $request->send();
         } catch (ConnectionErrorException $exception) {
             return false;
         }
         if ($response->hasErrors()) {
             return false;
         }
         return $response->body;
     });
     if (is_object($release)) {
         return $release->tag_name;
     }
     return false;
 }
예제 #24
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;
 }
예제 #25
0
 /**
  * Cache results.
  *
  * @param  \Closure  $callback
  *
  * @return array
  */
 protected function cacheResults(Closure $callback)
 {
     return $this->cache->remember($this->getCacheKey(), $this->cacheDuration, $callback);
 }
예제 #26
0
 /**
  * Remember the result value for a given closure
  * @param $key
  * @param $minutes
  * @param $callback
  *
  * @return mixed
  */
 public function cacheRemember($key, $minutes, $callback)
 {
     return $this->cache->remember($this->cachePrefix($key), $minutes, $callback);
 }
예제 #27
0
 /**
  * Get an item from the cache, or store the default value.
  *
  * @param  string        $key
  * @param  \DateTime|int $minutes
  * @param  \Closure      $callback
  * @return mixed
  */
 public function remember($key, $minutes, Closure $callback)
 {
     return $this->cache->remember($key, $minutes, $callback);
 }
예제 #28
0
 /**
  * @param $version
  * @param $package
  *
  * @return array
  */
 public function getIndex($version, $package)
 {
     return $this->cache->remember($version . $package . 'index', 60, function () use($version, $package) {
         return $this->repository->getIndex($version, $package);
     });
 }