简体   繁体   English

Codeigniter网页缓存

[英]Codeigniter web page caching

How can i cache a particular part of the web page, I know how CI caching mechanism works also i am aware of Partial Caching. 我如何缓存网页的特定部分,我知道CI缓存机制的工作方式,我也知道部分缓存。

Assume that we have a page with some dynamic data associated with. 假设我们有一个页面,其中包含一些动态数据。 If i used caching then i cannot get the actual data on page refresh. 如果我使用缓存,则无法获取页面刷新时的实际数据。

How can i override this problem ? 我该如何解决这个问题?

I have one idea in my mind, While inserting the data just keep another field, lets say MD5_CONTENTS which will store the MD5 hash of the contents ( Normally form fields ). 我有一个主意,在插入数据时只保留另一个字段,假设MD5_CONTENTS将存储内容的MD5哈希(通常是表单字段)。 And next time on update i can compare the MD5 strings to determine changes. 下次更新时,我可以比较MD5字符串以确定更改。 If changes are found then delete the cache file. 如果找到更改,则删除缓存文件。

I dont know this is gonna work or not, But its littlebit hard for my current implementation. 我不知道这是否行得通,但是对于我当前的实现来说,这有点困难。

What is the best method to achieve Partial Caching ? 什么是实现部分缓存的最佳方法?

Thanks 谢谢

Would the caching driver do the trick? 缓存驱动程序会成功吗?

http://ellislab.com/codeigniter/user-guide/libraries/caching.html http://ellislab.com/codeigniter/user-guide/libraries/caching.html

$this->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file'));

if ( ! $foo = $this->cache->get('foo'))
{
     echo 'Saving to the cache!<br />';
     $foo = 'foobarbaz!';

     // Save into the cache for 5 minutes
     $this->cache->save('foo', $foo, 300);
}

echo $foo; 

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

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