简体   繁体   English

Codeigniter缓存?

[英]Codeigniter caching?

I'm trying to make my site faster, because I want it to load as fast as posable. 我试图使我的网站更快,因为我希望它的加载速度尽可能快。 I'm having a bit of trouble with caching though. 我在缓存方面遇到了一些麻烦。 I was trying to work with this , but it seems that that caches the whole page and my content changes quite a bit. 我正在尝试使用 ,但是似乎可以缓存整个页面,并且我的内容发生了很大变化。 Is it possible for me to only cach certain views that I know will not be changing? 我是否可以只听取我知道不会改变的某些观点? Like the header, footer and the main home page. 像页眉,页脚和主页一样。

The point of CI caching is to reduce the number of database queries, any time-consuming PHP calculations, etc... Basically, it will render a plain HTML page from your controller (and all the views it calls, of course). CI缓存的目的是减少数据库查询的数量,减少任何费时的PHP计算等。基本上,它将从控制器(以及它调用的所有视图)呈现纯HTML页面。 So, it won't really speed up your header and footer, unless you pull the data for them from the database or anythings that dynamic and heavy... but any modern browser will cache that for you unless you specifically disallow caching. 因此,除非您从数据库或任何动态而繁重的数据中提取数据,否则它实际上不会加快页眉和页脚的速度,但是除非您明确禁止缓存,否则任何现代浏览器都将为您缓存它。

So, the bottom line, CI caching allows caching of the full pages only, no separate parts. 因此,最重要的是,CI缓存仅允许缓存整个页面,没有单独的部分。 Of course, there are alternative ways to achieve what you wanted, for example you can make the header and the footer separate controllers, put caching in them, and call them by AJAX... but I'm not sure it's worth it. 当然,还有其他方法可以实现所需的功能,例如,您可以将页眉和页脚分开设置控制器,将其放入缓存中,然后通过AJAX进行调用...但是我不确定是否值得。

using extentions this is possible 使用扩展这是可能的

https://github.com/philsturgeon/codeigniter-cache https://github.com/philsturgeon/codeigniter-cache

usually the displaying isue too much of an issue, its the generation of the data which needs to be displayed which takes longer and benefits most from caching. 通常情况下,显示问题太多了,需要显示的数据生成时间更长,并且从缓存中受益最大。

A little late to the conversation, but have you taken a look at database cache? 谈话有点晚了,但是您是否看过数据库缓存? A lot of the web page delay can come from heavy db queries. 大量的数据库查询可能导致许多网页延迟。 Caching the results opens up dynamic views. 缓存结果将打开动态视图。

This is helpful when you are managing sessions. 在管理会话时,这很有用。

$this->db->cache_on();

Place this in your model instead of controller. 将此放置在模型中而不是控制器中。 Make sure you have a writable db-cache folder in your app directory as well. 确保在应用目录中也有一个可写的db-cache文件夹。

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

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