public function put($request, $file)
 {
     if ($file) {
         $this->cache->put($this->makeCacheKey($request), $file, Carbon::now()->addMinutes(env('CACHE_EXPIRE_MINUTES')));
     }
     return $this;
 }
 /**
  * Put a key value pair in the cache
  *
  * @param string $key
  * @param mixed $value
  * @param integer $minutes
  *
  * @return mixed
  */
 public function put($key, $value, $minutes = null)
 {
     if (is_null($minutes)) {
         $minutes = $this->minutes;
     }
     return $this->cache->put($key, $value, $minutes);
 }
 /**
  * Prevent further posts with the same signature
  *
  * @return mixed
  */
 protected function nextAndPreventReplay(Closure $next)
 {
     $response = $next($this->request);
     $expire = Carbon::createFromTimestamp($this->request->get('timestamp'))->addHours($this->cacheDays * 24);
     $this->cache->put($this->getCacheKey(), 1, $expire);
     return $response;
 }
Example #4
0
 /**
  * Store a return url in the cache if provided.
  *
  * @param  TemporaryCredentials  $temp
  *
  * @return void
  */
 protected function storeReturnUrl(TemporaryCredentials $temp)
 {
     if ($url = $this->request->get('return_url')) {
         $key = 'oauth_return_url_' . $temp->getIdentifier();
         $this->cache->put($key, $url, ProviderContract::CACHE_TTL);
     }
 }
Example #5
0
 /**
  * Put
  * @param $key
  * @param $value
  * @param null $minutes
  * @return mixed
  */
 public function put($key, $value, $minutes = null)
 {
     if (is_null($minutes)) {
         $minutes = $this->minutes;
     }
     if ($this->cacheDriver == "file") {
         return $this->cache->put($key, $value, $minutes);
     }
     return $this->cache->tags($this->tag)->put($key, $value, $minutes);
 }
Example #6
0
 /**
  * Render the homepage view for displaying.
  *
  * @param  string $name
  * @return string
  */
 public function render($name, $subname = 'Home.Content')
 {
     if ($this->cache->has('home.content')) {
         $content = $this->cache->get('home.content');
     } else {
         $slides = App::make('Lib\\Slides\\SlideRepository')->get();
         $news = App::make('Lib\\News\\NewsRepository')->latest(8);
         $content = $this->view->make($subname)->with('slides', $slides)->with('news', $news)->with('categories', $this->getCategories())->render();
         $this->cache->put('home.content', $content, 2880);
     }
     return $this->view->make($name)->with('content', $content);
 }
Example #7
0
 /**
  * Sets a cache key to the specified locale.
  *
  * @param Model $locale
  */
 protected function setCacheLocale(Model $locale)
 {
     if (!$this->cache->has($locale->code)) {
         $id = sprintf('translation.%s', $locale->code);
         $this->cache->put($id, $locale, $this->cacheTime);
     }
 }
Example #8
0
 /**
  * @return \Illuminate\Support\Collection
  */
 protected function compileScriptMaterial()
 {
     $files = new Collection();
     $this->layoutJsMaterial->merge($this->defaultJsMaterial)->merge($this->extendJsMaterial)->each(function ($value) use($files) {
         $files->push($this->findPath($value));
     });
     $code = md5($files);
     $this->dispatcher->listen('kernel.handled', function () use($code, $files) {
         $dictionary = new Collection();
         $dictionary->push($this->application->publicPath());
         $dictionary->push('cache');
         $dictionary = $this->pathSplit($code, '2,2,2,2,2,2', $dictionary);
         $dictionary = $dictionary->implode(DIRECTORY_SEPARATOR);
         if (!$this->files->isDirectory($dictionary)) {
             $this->files->makeDirectory($dictionary, 0755, true, true);
         }
         $file = $dictionary . DIRECTORY_SEPARATOR . Str::substr($code, 12, 20) . '.js';
         $key = 'cache.script.' . $code;
         if (!$this->files->exists($file) || !$this->cache->has($key) && $this->application->inDebugMode()) {
             $content = $this->compileScript($files);
             $expires = Carbon::now()->addMinutes(10);
             $this->cache->put($key, $content, $expires);
             file_put_contents($file, $content);
         }
     });
     return $this->pathSplit($code, '2,2,2,2,2,2,20', Collection::make(['cache']))->implode('/') . '.js';
 }
Example #9
0
 /**
  * Render weather widget.
  *
  * @param  array  $options
  * @return string
  */
 public function generate($options = array())
 {
     // Get options
     $options = array_merge($this->config['defaults'], $options);
     // Unify units
     $options['units'] = strtolower($options['units']);
     if (!in_array($options['units'], array('metric', 'imperial'))) {
         $options['units'] = 'imperial';
     }
     // Create cache key
     $cacheKey = 'Weather.' . md5(implode($options));
     // Check cache
     if ($this->config['cache'] && $this->cache->has($cacheKey)) {
         return $this->cache->get($cacheKey);
     }
     // Get current weather
     $current = $this->getWeather($options['query'], 0, $options['units'], 1);
     if ($current['cod'] !== 200) {
         return 'Unable to load weather';
     }
     // Get forecast
     $forecast = $this->getWeather($options['query'], $options['days'], $options['units']);
     // Render view
     $html = $this->view->make("{$this->config['views']}.{$options['style']}", array('current' => $current, 'forecast' => $forecast, 'units' => $options['units'], 'date' => $options['date']))->render();
     // Add to cache
     if ($this->config['cache']) {
         $this->cache->put($cacheKey, $html, $this->config['cache']);
     }
     return $html;
 }
Example #10
0
 /**
  * Register the collections cache and store each of the cached items on
  * the collection.
  * 
  * @return \JasonLewis\Website\DocumentCollection
  */
 public function registerCollectionCache()
 {
     // If the cache does not contain the items identifier then we'll use the loader
     // to load all items and store the items in the cache.
     $items = $this->cache->remember($this->identifier, $this->expires, function () {
         $items = $this->loader->load();
         // Spin over each of the items and store the individual articles in the cache
         // as well so that when we request a single item we can quickly pull it from
         // the cache.
         foreach ($items as $item) {
             $this->cache->put($item->getSlug(), $item, $this->expires);
         }
         return $items;
     });
     // With the cached items we'll now spin over each one and using the array access
     // assign it to our document collection.
     foreach ($items as $item) {
         $this[$item->getSlug()] = $item;
     }
     return $this;
 }
 /**
  * Return the price of an item using Steam's API
  *
  * @param  integer $appId
  * @param  string  $itemName
  * @param  bool    $onlyPrice Return only the lowest price
  * @return stdClass
  */
 public function getPrice($appId = 730, $itemName, $onlyPrice = false)
 {
     $cacheKey = 'steamprice.item.' . str_slug($itemName);
     // Check if item price is cached
     if ($this->cache->has($cacheKey)) {
         $data = $this->cache->get($cacheKey);
     } else {
         // Grab the item price and cache it
         $url = $this->getItemPriceUrl($itemName, $appId);
         // No result
         if (!($json = @file_get_contents($url))) {
             // Cache null for 30 seconds to not harass the Steam servers
             $this->cache->put($cacheKey, null, 30);
             return null;
         }
         $json = str_replace($this->currencyHtmlTags, '', $json);
         $data = json_decode($json);
         $this->cache->put($cacheKey, $data, Config::get('braseidon.steam-item-prices.cache_time'));
     }
     if ($onlyPrice === true) {
         $data = !isset($data->lowest_price) ? null : $data->lowest_price;
     }
     return $data;
 }
Example #12
0
 /**
  * Update the "remember me" token for the given user in storage.
  *
  * @param  \Illuminate\Contracts\Auth\Authenticatable $user
  * @param  string $token
  * @return void
  */
 public function updateRememberToken(Authenticatable $user, $token)
 {
     $this->cache->put('user' . $user->getAuthIdentifier() . '_token_' . $token, $user, 60 * 24);
 }
 /**
  * Adds/updates a setting.
  *
  * @param   string $key
  * @param   string $value
  * @return  void
  */
 public function set($key, $value)
 {
     // update the local cache
     $this->settings[$key] = $value;
     $this->cache->put($this->key($key), $value, 0);
 }
Example #14
0
 /**
  * Store an item in the cache for a given number of minutes.
  *
  * @param string $key
  * @param mixed  $value
  * @param int    $minutes
  */
 public function put($key, $value, $minutes)
 {
     $this->cache->put($this->prefix . $key, $value, $minutes);
 }
 /**
  * Update the "remember me" token for the given user in storage.
  *
  * @param  \Illuminate\Auth\UserInterface  $user
  * @param  string  $token
  * @return void
  */
 public function updateRememberToken(UserInterface $user, $token)
 {
     //We use the cache because it's easier than managing old file deletion.
     //Such a micro functionnality souldn't expect more than 24 hours autologin
     $this->cache->put('user' . $user->getAuthIdentifier() . '_token_' . $token, $user, 60 * 24);
 }
Example #16
0
 public function start(UserInterface $user)
 {
     $this->cache->put($this->getCacheKey($user->getAccessToken()), $user->getKey(), Config::get('session.lifetime'));
 }