/** * Get info from a specify url and cache that using laravel cache manager. * * @param string $url * @param null|array $options * @return mixed */ public function cache($url, array $options = null) { $lifetime = array_get($options, 'lifetime', 60); array_forget($options, 'lifetime'); $self = $this; return $this->cache->remember($url, $lifetime, function () use($self, $url, $options) { return $self->get($url, $options); }); }
/** * Returns the cached content if NOT running locally. * * @param string $key * @param mixed $value * @param int $time * @return mixed */ private function cached($key, $value, $time = 5) { if (App::environment('local') === false) { return $this->cache->remember($key, $time, function () use($value) { return $value; }); } else { return $value; } }
/** * To get all columns on caching * * @param \Illuminate\Database\Eloquent\Model $model * @return array */ protected function getColumnsOnCache(Model $model) { /** * In normal scenario tables and columns often is not changed. * Therefore every time it is not need to access the database for knowing * columns name. We don't want make preoccupy/busy to the database. */ $fullKey = $this->getFullName($model); return $this->cache->remember($fullKey, $this->getRememberTime(), function () use($model) { return $this->builder->getColumnListing($model->getTable()); }); }
protected function data() { if (!$this->loaded) { $this->data = $this->original = $this->cache->remember('fluxbb.config', 24 * 60, function () { $data = $this->database->table('config')->get(); $cache = array(); foreach ($data as $row) { $cache[$row->conf_name] = $row->conf_value; } return $cache; }); $this->loaded = true; } return $this->data; }
/** * 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) { if ($this->enabled) { return $this->cache->remember($key, $minutes, $callback); } return $callback; }
/** * Retrieve a model object by its reference value, if it has one * * @param $reference * @return null */ public function retrieveByReference($reference) { $referenceColumn = $this->referenceIdColumnName(); if ($this->model->isFillable($referenceColumn)) { $key = $this->resourceName . '.' . $referenceColumn . '.' . $reference; return $this->cache->remember($key, 10, function () use($reference) { return $this->model->where($this->referenceIdColumnName(), $reference)->first(); }); } else { return null; } }
/** * Get an item from the cache, or store the default value. * * @param string $key * @param \DateTime|int $minutes * @param \Closure $callback * @return mixed * @static */ public static function remember($key, $minutes, $callback) { return \Illuminate\Cache\Repository::remember($key, $minutes, $callback); }
/** * Get an item from the cache, or store the default value. * * @param mixed $key * @param \DateTime|int $minutes * @param \Closure $callback * @return mixed */ public function remember($key, $minutes, Closure $callback) { if (is_array($key)) { return $this->rememberMany($key, $minutes, $callback); } return parent::remember($key, $minutes, $callback); }
/** * To get all lang models on the cache driver * * @return \Illuminate\Database\Eloquent\Collection */ protected function getCachedLangModels() { $key = $this->getKeyOfCachedLangModel($this->getMainModel()->langModels()->getRelated()); return $this->cache->remember($key, $this->getRememberTime(), function () { return $this->getAllLangModels()->getRelated()->all(); }); }
/** * @author Rohit Arora * * @param array $columns * * @return Collection */ public function fetch($columns = [ALL_FIELDS]) { return $this->Cache->remember('posts-' . implode('-', $columns), 60, function () use($columns) { return $this->PostContract->fetch($columns); }); }