Exemplo n.º 1
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));
         });
     }
 }
Exemplo n.º 2
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);
     });
 }
Exemplo n.º 3
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]);
 }
 /**
  * @return \Illuminate\Http\Response
  */
 public function render()
 {
     if ($this->getUseCache()) {
         $data = $this->cache->remember($this->getCacheKey(), $this->getCacheLifetime(), function () {
             return $this->buildXML();
         });
     } else {
         $data = $this->buildXML();
     }
     $headers = ['Content-type' => 'text/xml; charset=utf-8'];
     return new Response($data, 200, $headers);
 }
Exemplo n.º 5
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;
 }
 /**
  * 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'];
     });
 }