Private Caching Methods
(bool) |
cached |
Returns TRUE is the cache image with the given name and language is available. |
(string) |
getcache |
Returns the given cache image, if available. |
(mixed) |
getdatacache |
Returns the data from the private cache, if available. |
(void) |
savecache |
Saves a cache image started earlier with cached() . |
(void) |
savedatacache |
Saves data to the private cache. |
cached
(bool) cached($name, $nls="")
(string) |
$name |
The name of the private cache image. |
(string) |
$nls |
The language of the private cache image. |
cached()
checks whether a private cache image with the given name is available for the current object. If it is, it will display that cached image and return true. If it isn't, it will start a new cache (using output buffering) and return false.
This function is most useful in a intranet or personalized website environment. When generating pages for a specific person, it is impossible to use the public cache system. With this function you can create small building blocks, which can be cached, and use them to build the entire page. Instead of caching the entire page, only the common elements are cached. It also makes it possible to cache pages that must not become public. Since the cache is called only after the credentials of the viewer are checked, the cached image is available only to authorized users.
savecache()
function. Otherwise Ariadne will complain.cached()
and savecache()
call. Example:
if(!cached("mycache")) { echo "Cache this!"; savecache(); }
getcache
(mixed) getcache($name, $nls='')
(string) |
$name |
The name of the private cache image. |
(string) |
$nls |
The language of the cache image. |
getcache()
returns the cached output if it exists and is still 'fresh'. If not, it will start the caching mechanism and return false.
<pinp>
if ( $image = $this->getcache( 'complex_stuff', $nls ) ) {
ldHeader( 'Content-Length: ' . strlen( $image ) );
echo $image;
} else {
// do complex stuff
echo $complex_stuff;
savecache(24);
}
</pinp>
getdatacache
(mixed) getdatacache($name)
(string) |
$name |
The name of the private cache data. |
getdatacache()
returns the cached data if it exists and is still 'fresh'. If not it will return false. It will not start the caching mechanism.
<pinp>
if ( ! $result = getdatacache('complex_calculation') ) {
$result = call('do.complex.calculation');
savedatacache('complex_calculation', $result, 24);
}
</pinp>
savecache
(void) savecache($time=2)
(int) |
$time |
The time, in hours, to keep the cache image 'fresh'. |
savecache()
stops the caching mechanism and saves the output generated between starting the cache en stopping it in the private cache. The name of the cache image is the name given when starting the cache with either cached()
or getcache()
.
savedatacache
(void) savedatacache($name, $data, $time=2)
(string) |
$name |
The name of the private cache image. |
(mixed) |
$data |
The language of the cache image. |
(int) |
$time |
The time, in hours, to keep the cache data 'fresh'. |
savedatacache()
saves the data in the private cache with the given name. The data is kept 'fresh' for the amount of hours specified.