Ejemplo n.º 1
0
 /**
  * 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);
     });
 }
Ejemplo n.º 2
0
 /**
  * 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;
     }
 }
Ejemplo n.º 3
0
 /**
  * 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());
     });
 }
Ejemplo n.º 4
0
 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;
 }
Ejemplo n.º 5
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)
 {
     if ($this->enabled) {
         return $this->cache->remember($key, $minutes, $callback);
     }
     return $callback;
 }
Ejemplo n.º 6
0
 /**
  * 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;
     }
 }
Ejemplo n.º 7
0
 /**
  * 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);
 }
Ejemplo n.º 8
0
 /**
  * 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);
 }
Ejemplo n.º 9
0
 /**
  * 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();
     });
 }
Ejemplo n.º 10
0
 /**
  * @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);
     });
 }