Example #1
0
 /**
  * Handle the command.
  *
  * @param CacheManager       $cache
  * @param FieldMigrator      $fields
  * @param StreamMigrator     $streams
  * @param AssignmentMigrator $assignments
  */
 public function handle(CacheManager $cache, FieldMigrator $fields, StreamMigrator $streams, AssignmentMigrator $assignments)
 {
     $assignments->reset($this->migration);
     $fields->reset($this->migration);
     $streams->reset($this->migration);
     $cache->flush();
 }
 public function put($request, $file)
 {
     if ($file) {
         $this->cache->put($this->makeCacheKey($request), $file, Carbon::now()->addMinutes(env('CACHE_EXPIRE_MINUTES')));
     }
     return $this;
 }
Example #3
0
 /**
  * Has
  * @param $key
  * @return bool
  */
 public function has($key)
 {
     if ($this->cacheDriver == "file") {
         return $this->cache->has($key);
     }
     return $this->cache->tags($this->tag)->has($key);
 }
 protected function addFileCacheDriver(CacheManager $cacheManager)
 {
     $cacheManager->extend(static::$fileDriverName, function ($app, array $cacheConfig) use($cacheManager) {
         $store = new AlternativeHierarchialFileCacheStore(new Filesystem(static::makeFileCacheAdapter($cacheConfig)), static::getPrefix($cacheConfig));
         return $cacheManager->repository($store);
     });
 }
Example #5
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;
 }
 /**
  * Perform post-registration booting of services.
  *
  * @return void
  */
 public function boot(CacheManager $cacheManager)
 {
     $cacheManager->extend('dummy', function ($app) {
         $prefix = $app['config']->get('cache.prefix');
         return $app['cache']->repository(new DummyCacheStore($prefix));
     });
 }
Example #7
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $this->laravel['events']->fire('cache:clearing');
     $this->cache->flush();
     $this->laravel['events']->fire('cache:cleared');
     $this->info('Application cache cleared!');
 }
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $this->cache->flush();
     $this->files->delete($this->laravel['config']['app.manifest'] . '/services.json');
     $this->laravel['events']->fire('cache:cleared');
     $this->info('Application cache cleared!');
 }
 /**
  * Return the cache instance with tags attached
  *
  * @return \Illuminate\Cache\CacheManager
  */
 protected function cache()
 {
     if (!method_exists($this->cache, 'tags')) {
         return $this->cache;
     }
     return $this->cache->tags($this->tag);
 }
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $storeName = $this->argument('store');
     $this->laravel['events']->fire('cache:clearing', [$storeName]);
     $this->cache->store($storeName)->flush();
     $this->laravel['events']->fire('cache:cleared', [$storeName]);
     $this->info('Application cache cleared!');
 }
 /**
  * Finish installation.
  *
  * @param Dispatcher   $events
  * @param CacheManager $cache
  * @return \Illuminate\View\View
  */
 public function finish(Dispatcher $events, CacheManager $cache)
 {
     $cache->store()->flush();
     $action = 'finish';
     $installers = $this->dispatch(new GetSeeders());
     $events->fire(new StreamsHasInstalled($installers));
     return view('anomaly.module.installer::process', compact('action', 'installers'));
 }
 public function handle()
 {
     $storeName = $this->config->get('laravel-responsecache.cacheStore');
     $this->laravel['events']->fire('responsecache:clearing', [$storeName]);
     $this->cache->store($storeName)->flush();
     $this->laravel['events']->fire('responsecache:cleared', [$storeName]);
     $this->info('Response cache cleared!');
 }
Example #13
0
 public static function getStore()
 {
     if (!static::$store) {
         $manager = new CacheManager(new ConfigContainer(array('db' => \DLModel::getConnectionResolver(), 'encrypter' => Encrypter::getInstance(), 'config' => array('cache.driver' => 'database', 'cache.prefix' => 'schema_', 'cache.stores.database' => array('driver' => 'database', 'connection' => 'default', 'table' => 'cache')))));
         static::$store = $manager->driver('database')->getStore();
     }
     return static::$store;
 }
Example #14
0
 public static function make()
 {
     if (is_null(self::$instance)) {
         $cacheManager = new CacheManager(array('files' => new FileSystem(), 'config' => array('cache.driver' => 'file', 'cache.path' => path('cache'), 'cache.prefix' => 'wordpress_')));
         $cache = $cacheManager->driver();
         self::$instance = new static($cache);
     }
     return self::$instance;
 }
Example #15
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     if (null !== ($key = $this->argument('key'))) {
         $this->keys = [$key];
     }
     foreach ($this->keys as $key) {
         $this->cacheManager->store()->forget($key);
     }
     $this->cacheManager->store()->tags(['dbQueryCache'])->flush();
     $this->info('Clear cache successfully!');
 }
Example #16
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 #17
0
 /**
  * Lookup an item in the API.
  *
  * @param string $item
  * @param array  $params
  *
  * @return object
  */
 public function lookup($id, $value = null, $params = array())
 {
     $cacheKey = $this->cacheKey('lookup', $this->getLookupParams($id, $value, $params));
     $cacheDuration = $this->iTunesConfig['cache'];
     if ($this->cache->has($cacheKey)) {
         return $this->cache->get($cacheKey);
     } else {
         return $this->cache->remember($cacheKey, $cacheDuration, function () use($id, $value, $params) {
             return json_encode(parent::lookup($id, $value, $params));
         });
     }
 }
Example #18
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function handle()
 {
     $tags = array_filter(explode(',', $this->option('tags')));
     $cache = $this->cache->store($store = $this->argument('store'));
     $this->laravel['events']->fire('cache:clearing', [$store, $tags]);
     if (!empty($tags)) {
         $cache->tags($tags)->flush();
     } else {
         $cache->flush();
     }
     $this->info('Cache cleared successfully.');
     $this->laravel['events']->fire('cache:cleared', [$store, $tags]);
 }
Example #19
0
 /**
  * @param $key
  * @param $value
  * @return bool
  */
 public function set($key, $value)
 {
     $setting = Setting::whereKey($key)->first();
     if (!is_object($setting)) {
         $setting = new Setting();
         $setting->key = $key;
     }
     $setting->value = $value;
     $setting->save();
     if ($this->application->isInstalled()) {
         $this->cache->forget($this->cache_key);
     }
     return true;
 }
Example #20
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 #21
0
 /**
  * Remove a locale from the cache.
  *
  * @param string $code
  */
 protected function removeCacheLocale($code)
 {
     $id = sprintf('translation.%s', $code);
     if ($this->cache->has($id)) {
         $this->cache->forget($id);
     }
 }
 /**
  * Load the inventory for a Steam ID
  *
  * @param  integer $steamId
  * @param  integer $appId
  * @param  integer $contextId
  * @return Json
  */
 public function loadInventory($steamId, $appId = 730, $contextId = 2)
 {
     if ($this->cache->tags($this->cacheTag)->has($steamId)) {
         $this->currentData = $this->cache->tags($this->cacheTag)->get($steamId);
         // Return the cached data
         return $this;
     }
     $inventory = $this->getSteamInventory($steamId, $appId, $contextId);
     if (is_array($inventory)) {
         $minutes = $this->cacheTime;
         $this->cache->tags($this->cacheTag)->put($steamId, $inventory, $minutes);
         $this->currentData = $inventory;
     } else {
         return false;
     }
     return $this;
 }
Example #23
0
 /**
  * Return the admin dashboard view.
  *
  * @return \Illuminate\View\View
  */
 public function showDashboard(CacheManager $cache)
 {
     $stats = ['Item stats' => ['Listed' => function ($range) use($cache) {
         return mustard_number($cache->remember('total_items', config('mustard.dashboard_cache'), function () use($range) {
             return Item::totalListed($range);
         }));
     }, 'Watched' => function ($range) use($cache) {
         return mustard_number($cache->remember('total_items', config('mustard.dashboard_cache'), function () use($range) {
             return Item::totalWatched($range);
         }));
     }], 'User stats' => ['Registered' => function ($range) use($cache) {
         return mustard_number($cache->remember('total_users', config('mustard.dashboard_cache'), function () use($range) {
             return User::totalRegistered($range);
         }));
     }, 'Sellers' => function ($range) use($cache) {
         return mustard_number($cache->remember('total_sellers', config('mustard.dashboard_cache'), function () use($range) {
             return User::totalSellers($range);
         }));
     }]];
     if (mustard_loaded('auctions')) {
         $stats['User stats']['Bidders'] = function ($range) use($cache) {
             return mustard_number($cache->remember('total_bidders', config('mustard.dashboard_cache'), function () use($range) {
                 return User::totalBidders($range);
             }));
         };
         $stats['Item stats']['Bids placed'] = function ($range) use($cache) {
             return mustard_number($cache->remember('total_bids_placed', config('mustard.dashboard_cache'), function () use($range) {
                 return \Hamjoint\Mustard\Auctions\Bid::totalPlaced($range);
             }));
         };
         $stats['Item stats']['Average bid amount'] = function ($range) use($cache) {
             return mustard_price($cache->remember('average_bids', config('mustard.dashboard_cache'), function () use($range) {
                 return \Hamjoint\Mustard\Auctions\Bid::averageAmount($range);
             }));
         };
     }
     if (mustard_loaded('commerce')) {
         $stats['User stats']['Buyers'] = function ($range) use($cache) {
             return mustard_number($cache->remember('total_buyers', config('mustard.dashboard_cache'), function () use($range) {
                 return User::totalBuyers($range);
             }));
         };
         $stats['Transaction stats']['Purchases'] = function ($range) use($cache) {
             return mustard_number($cache->remember('total_purchases', config('mustard.dashboard_cache'), function () use($range) {
                 return \Hamjoint\Mustard\Commerce\Purchase::totalCreated($range);
             }));
         };
         $stats['Transaction stats']['Average amount'] = function ($range) use($cache) {
             return mustard_price($cache->remember('average_purchases', config('mustard.dashboard_cache'), function () use($range) {
                 return \Hamjoint\Mustard\Commerce\Purchase::averageAmount($range);
             }));
         };
     }
     $ranges = ['Today' => strtotime('midnight'), 'This week' => strtotime('monday this week'), 'This month' => strtotime('midnight first day of this month'), 'This year' => strtotime(date('Y') . '/01/01'), 'Overall' => 0];
     return view('mustard::admin.dashboard', ['ranges' => $ranges, 'stats' => $stats]);
 }
 /**
  * Flush cache for tags.
  *
  * @param  mixed $tags
  *
  * @return bool
  */
 public function flush($tags = null)
 {
     if ($tags !== null) {
         $tags = is_array($tags) ? $tags : func_get_args();
     } else {
         $tags = $this->tags;
     }
     return $this->cache->tags($tags)->flush();
 }
Example #25
0
 /**
  * Get the token credentials for the request.
  *
  * @return \League\OAuth1\Client\Credentials\TokenCredentials
  */
 protected function getToken()
 {
     // We have a stateless app without sessions, so we use the cache to
     // retrieve the temp credentials for man in the middle attack
     // protection
     $key = 'oauth_temp_' . $this->request->get('oauth_token');
     $temp = $this->cache->get($key, '');
     return $this->server->getTokenCredentials($temp, $this->request->get('oauth_token'), $this->request->get('oauth_verifier'));
 }
Example #26
0
 /**
  * Execute caching against database query.
  *
  * @see config/project.php's cache section.
  *
  * @param string $key
  * @param int $minutes
  * @param \App\Model|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder
  *        |\Illuminate\Database\Eloquent\Relations\Relation $query
  * @param string $method
  * @param mixed ...$args
  * @return mixed
  */
 protected function cache($key, $minutes, $query, $method, ...$args)
 {
     $args = !empty($args) ? implode(',', $args) : null;
     if (config('project.cache') === false) {
         return $query->{$method}($args);
     }
     return $this->cache->remember($key, $minutes, function () use($query, $method, $args) {
         return $query->{$method}($args);
     });
 }
Example #27
0
 /**
  * Get an item from the cache manager, or store the default value.
  *
  * @param  string   $key
  * @param  \Closure $callback
  *
  * @return mixed
  */
 public function getCache($key, Closure $callback)
 {
     // Skip cache for development
     if (config('app.debug')) {
         return $this->getLocalCache($key, $callback);
     }
     $key = $this->website->id . '-' . $key;
     $tags = $this->getCacheTags('pages');
     return $this->cacheManager->tags($tags)->rememberForever($key, $callback);
 }
 /**
  * Create an instance of the Redis cache driver.
  *
  * @param  array $config
  *
  * @return \Illuminate\Cache\RedisStore|\Illuminate\Cache\FileStore
  */
 protected function createRedisDriver(array $config)
 {
     $redis = $this->app['redis'];
     $connection = \Illuminate\Support\Arr::get($config, 'connection', 'default') ?: 'default';
     $store = new RedisStore($redis, $this->getPrefix($config), $connection);
     try {
         $store->getRedis()->ping();
         return $this->repository($store);
     } catch (Exception $e) {
         event('redis.unavailable', null);
         return parent::createFileDriver(\Config::get('cache.stores.file'));
     }
 }
 /**
  * Downloads the latest exchange rates file from openexchangerates.org
  *
  * @return object
  */
 public function setRates()
 {
     // Avoid instance issues
     $self = $this;
     // Cache the currencies
     return $this->rates = $this->cache->remember('currencies', $this->getExpires(), function () use($self) {
         if (!($appId = $self->getAppId())) {
             throw new Exception('OpenExchangeRates.org requires an app key.');
         }
         $client = new Client(['base_url' => $self->getUrl()]);
         $data = $client->get("latest.json?app_id={$appId}")->json();
         return $data['rates'];
     });
 }
 /**
  * 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;
 }