当前位置: 首页>>代码示例>>PHP>>正文


PHP CacheManager::remember方法代码示例

本文整理汇总了PHP中Illuminate\Cache\CacheManager::remember方法的典型用法代码示例。如果您正苦于以下问题:PHP CacheManager::remember方法的具体用法?PHP CacheManager::remember怎么用?PHP CacheManager::remember使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Cache\CacheManager的用法示例。


在下文中一共展示了CacheManager::remember方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: lookup

 /**
  * 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));
         });
     }
 }
开发者ID:vinelab,项目名称:itunes,代码行数:20,代码来源:LaravelAgent.php

示例2: cache

 /**
  * 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);
     });
 }
开发者ID:linuxssm,项目名称:l5essential,代码行数:23,代码来源:Controller.php

示例3: showDashboard

 /**
  * 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]);
 }
开发者ID:hamjoint,项目名称:mustard,代码行数:61,代码来源:AdminController.php

示例4: render

 /**
  * @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);
 }
开发者ID:cviebrock,项目名称:laravel-news-sitemap,代码行数:15,代码来源:NewsSitemap.php

示例5: registerCollectionCache

 /**
  * 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;
 }
开发者ID:bamper,项目名称:website,代码行数:27,代码来源:Collection.php

示例6: setRates

 /**
  * 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'];
     });
 }
开发者ID:Riesjart,项目名称:converter,代码行数:19,代码来源:OpenExchangeRatesExchanger.php


注:本文中的Illuminate\Cache\CacheManager::remember方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。