mirror of
https://github.com/bcit-ci/CodeIgniter.git
synced 2025-02-20 11:13:29 +08:00
...
parent
a30ea898e0
commit
157d699043
@ -3,7 +3,22 @@
|
||||
[h3]Introduction[/h3]
|
||||
Ok, here goes: this is a library to add page-fragment caching capabilities to codigniter. That is: allow you, the programmer to mark a part of a view to be cached independently of other bits of the page. The idea is pretty simple, but I wanted the syntax to be as lean as possible, and to make usage as transparent as possible.
|
||||
|
||||
First, the code, place it in the libraries folder and name the file Cache_fragment.php:
|
||||
Usage: fragment caching is invoked via start/end markers in the view.
|
||||
|
||||
[code]
|
||||
<?php
|
||||
// some un-cached code
|
||||
// some more un-cached code
|
||||
|
||||
<? if($this->cache_fragment->start(1)){ ?>
|
||||
// stuff you wish to cache
|
||||
<? } $this->cache_fragment->end();?>
|
||||
|
||||
// even more un-cached code
|
||||
[/code]
|
||||
|
||||
|
||||
The library: Place it in libraries/Cache_fragment.php
|
||||
|
||||
[code]
|
||||
<?php
|
||||
@ -68,21 +83,9 @@ class Cache_fragment{
|
||||
?>
|
||||
[/code]
|
||||
|
||||
After that, you can either add 'fragment' to the autoload, or do:
|
||||
Of course, you can either add 'fragment' to the autoload, or do:
|
||||
[code]$this->load->library('cache_fragment')[/code]
|
||||
|
||||
now for usage, this happens inside the view:
|
||||
[code]
|
||||
<?php
|
||||
// some un-cached code
|
||||
// some more un-cached code
|
||||
|
||||
<? if($this->cache_fragment->start(1)){ ?>
|
||||
// stuff you wish to cache
|
||||
<? } $this->cache_fragment->end();?>
|
||||
|
||||
// even more un-cached code
|
||||
[/code]
|
||||
|
||||
[b]Note[/b]: The number fed to the ->start(x) function is the expiration time of the cache in minutes.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user