本文整理匯總了PHP中Illuminate\Cache\CacheManager::rememberForever方法的典型用法代碼示例。如果您正苦於以下問題:PHP CacheManager::rememberForever方法的具體用法?PHP CacheManager::rememberForever怎麽用?PHP CacheManager::rememberForever使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Illuminate\Cache\CacheManager
的用法示例。
在下文中一共展示了CacheManager::rememberForever方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: get
/**
* @param $key
* @param null $default
* @return null
*/
public function get($key, $default = null)
{
try {
$settings = $this->cache->rememberForever($this->cache_key, function () {
$settings = Setting::get(['key', 'value']);
$arr = [];
foreach ($settings as $setting) {
$arr[$setting->key] = $setting->value;
}
return $arr;
});
return isset($settings[$key]) ? $settings[$key] : $default;
} catch (Exception $ex) {
return null;
}
}
示例2: fetchAndCache
/**
* Cache all configurations.
*
* @return void
*/
public function fetchAndCache()
{
$this->removeCache();
$configs = $this->cache->rememberForever('cartalyst.config', function () {
return $this->database->table($this->databaseTable)->get();
});
$cachedConfigs = [];
foreach ($configs as $key => $config) {
$value = $this->parseValue($config->value);
$cachedConfigs[$config->item] = $value;
parent::set($config->item, $value);
}
$this->cachedConfigs = $cachedConfigs;
}
示例3: rememberForever
/**
* @param $key
* @param $data
*
* @return mixed
*/
public function rememberForever($key, $data)
{
return $this->cache->rememberForever($key, function () use($data) {
return $data;
});
}