Codeigniter- cache view into a view

落花浮王杯 提交于 2019-12-22 06:47:39

问题


i'm wondering if it's possible to cache a view which is loaded inside another view.

I do:

view.php:

<div>
<?php echo $this->load->view('modules/new_view'); ?>
</div>

so view.php requires a new view inside himself, can i cache the views/modules/new_view.php content?


回答1:


Codeigniter has Web Page Caching

CodeIgniter lets you cache your pages in order to achieve maximum performance.

Although CodeIgniter is quite fast, the amount of dynamic information you display in your pages will correlate directly to the server resources, memory, and processing cycles utilized, which affect your page load speeds. By caching your pages, since they are saved in their fully rendered state, you can achieve performance that nears that of static web pages.

To do it you would use the code below where n is the number of minutes you wish the page to remain cached between refreshes. You can place it anywhere within a function.

$this->output->cache(n);

Update

To cache just a portion of the page, or just a single view, you can use CodeIgniter-Cache.

CodeIgniter-Cache is a partial caching library for CodeIgniter. It allows you to write and get chunks of data to and from the filesystem. By storing complex or large chunks of data in serialized form on the file system you can relieve stress from the database or simply cache Twitter calls.

Another alternative

MP Cache: Simple flexible Caching of parts of code



来源:https://stackoverflow.com/questions/18192259/codeigniter-cache-view-into-a-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!