本文整理汇总了PHP中Cache::forever方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::forever方法的具体用法?PHP Cache::forever怎么用?PHP Cache::forever使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cache
的用法示例。
在下文中一共展示了Cache::forever方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
public function generate($args)
{
if (count($args) != 1) {
die(self::$usageMessage);
}
$model = $args[0];
$table = Str::plural(Str::lower($model));
$options = array('Model' => $model, 'Table' => $table, 'DefaultField' => 'text', 'ParentID' => 'parent_id', 'Leaf' => 'leaf');
$r = new ReflectionClass($model);
preg_match_all('#@(.*?)\\n#s', $r->getDocComment(), $annotations);
if (!empty($annotations)) {
foreach ($annotations[0] as $annotation) {
preg_match('#@(?P<name>\\w+)[ ]*(\\([ ]*(?P<value>\\w+)[ ]*\\))?\\n#s', $annotation, $a);
if (array_key_exists($a['name'], $options)) {
$options[$a['name']] = $a['value'];
}
}
}
$columns = DB::query('SHOW columns from ' . $table);
if (Cache::has('ext' . $model, $columns)) {
$was_cached = true;
} else {
Cache::forever('ext' . $model, $columns);
$was_cached = false;
}
// Generate code
$this->generateExtModel($columns, $model, $options);
$this->generateGrid($columns, $model, $options, $was_cached);
$this->generateForm($columns, $model, $options, $was_cached);
$this->generateTree($model, $options, $was_cached);
/**************************************************************/
echo 'Task executed successfully';
}
示例2: render
public function render()
{
$key = md5($this->getPath());
$lastModified = $this->files->lastModified($this->getPath());
$generate = false;
if ($lastModifiedCache = \Cache::get("{$key}.lastmodified", false) !== false && \Cache::has($key)) {
if ($lastModified !== $lastModified) {
$generate = true;
}
} else {
$generate = true;
}
if (config('app.debug')) {
$generate = true;
}
$rendered = '';
if ($generate === true) {
$rendered = $this->parser->parse($this->files->get($this->getPath()));
\Cache::forever($key, $rendered);
\Cache::forever("{$key}.lastmodified", $lastModified);
} else {
$rendered = \Cache::get($key, false);
}
return $rendered;
}
示例3: get
/**
* Fetch setting
*
* @param $key
* @return null
*/
public function get($key)
{
/**
* Setup cache key
*/
$cacheKey = 'setting_' . md5($key);
/**
* Check if in cache
*/
if (\Cache::has($cacheKey)) {
return \Cache::get($cacheKey);
}
/**
* Fetch from database
*/
$setting = Setting::where('key', '=', $key)->first();
/**
* If a row was found, return the value
*/
if (is_object($setting) && $setting->getId()) {
/**
* Store in cache
*/
\Cache::forever($cacheKey, $setting->getValue());
/**
* Return the data
*/
return $setting->getValue();
}
return null;
}
示例4: testConfigReadsValuesFromCache
public function testConfigReadsValuesFromCache()
{
Cache::forever('config:all', 'foo');
$config = App::make('App\\Models\\Config');
$value = $config->all();
$this->assertSame('foo', $value);
}
示例5: _setModuleList
private function _setModuleList()
{
if (\Cache::has('modules.backend.list')) {
$this->_moduleList = \Cache::get('modules.backend.list');
return;
}
$moduleDir = app_path() . '/../modules/';
$result = array();
if ($handle = opendir($moduleDir)) {
while (false !== ($dir = readdir($handle))) {
if ($dir != '.' && $dir != '..') {
if (is_dir($moduleDir . $dir)) {
$backendData = false;
if (file_exists($moduleDir . $dir . '/backend.json')) {
$backendData = json_decode(file_get_contents($moduleDir . $dir . '/backend.json'));
}
$result[] = ['name' => $dir, "dir" => $moduleDir . $dir, 'backend' => $backendData];
}
}
}
closedir($handle);
}
$this->_moduleList = $result;
\Cache::forever('modules.backend.list', $result);
}
示例6: run
/**
* Runs all jobs that do not have a cool down.
* Returns false or the number of executed jobs.
*
* @return boolean|int
*/
public function run()
{
$now = time();
if ($this->cache->has($this->cacheKey)) {
$executed = $this->cache->get($this->cacheKey);
if ($now - $executed < $this->coolDown * 60) {
return false;
}
}
$this->cache->forever($this->cacheKey, $now);
$counter = 0;
foreach ($this->jobs as $name => $jobBag) {
$job = $this->getOrMake($name);
$key = $this->makeCacheKey($name);
$executed = null;
if ($this->cache->has($key)) {
$executed = $this->cache->get($key);
if ($now - $executed < $job->getInterval() * 60) {
continue;
}
}
if ($job->getActive()) {
$now = time();
$job->run($executed);
$this->cache->forever($key, $now);
$counter++;
}
}
return $counter;
}
示例7: setCache
/**
* 设置缓存
* @param string $cachename
* @param mixed $value
* @param int $expired
* @return boolean
*/
public static function setCache($cachename, $value, $expired = null)
{
$data = array('value' => $value);
if ($expired) {
$data['expires_at'] = time() + $expired;
}
\Cache::forever($cachename, json_encode($data));
}
示例8: update
public function update(Request $request)
{
$this->authorize('authorizeAccess', 'contactus');
$this->contactus->update($request->except('_token'));
$contactInfo = $this->contactus->first();
\Cache::forget('contactusInfo');
\Cache::forever('contactusInfo', $contactInfo);
return redirect()->back()->with('success', 'Contact Us Information has been updated');
}
示例9: getDefaultCityList
private function getDefaultCityList($country_code, $province_code)
{
$cityCodes = \Cache::get('bgcountry_city_' . $country_code . '_' . $province_code);
if (!$cityCodes) {
$cityCodes = $this->db->table('bgcity')->where(strlen($country_code) == 2 ? 'cty_code_2' : 'cty_code_3', '=', $country_code)->where(strlen($province_code) < 4 ? 'prov_short_code' : 'prov_long_code', '=', $province_code)->orderBy('city_name')->lists('city_name', $this->city_value_field);
\Cache::forever('bgcountry_city_' . $country_code . '_' . $province_code, $cityCodes);
}
return $cityCodes;
}
示例10: get
public static function get($arrArg = [])
{
if (Cache::has('categories')) {
$cache = Cache::get('categories');
} else {
$cache = self::getRecursive($arrArg);
Cache::forever('categories', $cache);
}
return $cache;
}
示例11: setCache
/**
* Cache the data.
*
* @param string $index
* @param array $data
* @param bool|int $period Hours
*
* @return bool
*/
public function setCache($index, $data, $period = false)
{
if (!$this->getCache($index)) {
$data = serialize($data);
if (!$period) {
\Cache::forever($index, $data);
}
}
return false;
}
示例12: getList
public function getList()
{
if (\Cache::has('widgets-list')) {
return \Cache::get('widgets-list');
} else {
$lists = $this->model->where('status', 1)->get();
\Cache::forever($lists, 'widgets-list');
return $lists;
}
}
示例13: __construct
/**
* Create a new URL Generator instance.
*
* @param \Illuminate\Routing\RouteCollection $routes
* @param \Illuminate\Http\Request $request
* @return void
*/
public function __construct(RouteCollection $routes, Request $request)
{
parent::__construct($routes, $request);
if (\Cache::has('assets-cdn::commitID')) {
$this->commitID = \Cache::get('assets-cdn::commitID');
} else {
$this->commitID = exec('git rev-parse HEAD');
\Cache::forever('assets-cdn::commitID', $this->commitID);
}
$this->cdnURL = config('assets-cdn.cdn-url');
}
示例14: page
public function page($page_index)
{
$isSuperAdmin = Auth::user()->isSuperAdmin();
$cacheKey = sprintf('wall.%d.%d', (bool) $isSuperAdmin, (int) $page_index);
$wallContent = Cache::get($cacheKey);
if (empty($wallContent)) {
$wallContent = View::make('partials.wall.page', array('isSuperAdmin' => $isSuperAdmin, 'page_index' => $page_index))->render();
Cache::forever($cacheKey, $wallContent);
}
return $wallContent;
}
示例15: initShopConfig
protected function initShopConfig()
{
if (!Cache::get('shop_config')) {
$shop_config = new Shop_config();
$shop_config_arr = $shop_config->all()->toArray();
foreach ($shop_config_arr as $key => $value) {
$shop_configs[$value['model']][$value['name']] = $value['value'];
}
Cache::forever('shop_config', $shop_configs);
}
}