简体   繁体   English

缓存无法正常工作

[英]cache is not working codeigniter

I am using the cache concept first time in codeigniter.I just followed the guidelines specified in codeigniter tutorials.But cache is not clearing after the time specified.Code is as follows: 我是第一次在codeigniter中使用缓存概念,只是遵循了codeigniter教程中指定的指导原则,但是指定的时间过后缓存并没有清除,代码如下:

$this->load->driver('cache');
if ( ! $foo = $this->cache->get('foo'))
{
 echo 'Saving to the cache!<br />';
 $foo = 'foobarbaz!';
 $this->cache->save('foo', $foo, 120);
}

echo $foo; 

After two minutes what will be the value of $foo? 两分钟后,$ foo的值是多少? Whether i have to do any other settings? 我是否还需要进行其他设置?

$cache = $this->cache->get('cache_data');
if ($cache) {
   echo $data = $this->cache->get('cache_data');
} else {
   echo 'Cache is not set';
   $this->cache->save('cache_data','data',3600);
}

I tried this code also.But every time it will execute the else part. 我也尝试过这段代码,但是每次都会执行else部分。

if ( ! $data = $this->cache->get('cache_data'))
{
     $data = array();// your data
     $this->cache->save('cache_data', $data, 600000);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM