Download |
Bug Tracking |
Source |
Documentation |
Forum |
Latest Changes |
Home
Pluf is fast, but sometimes, you need to interact wiht other servers or run complex operations. To avoid delay in rendering your pages, you should cache the results of the operation to avoid regenerating the values at each page display. The cache framework is doing this for you.
This is a typical usage:
$cache = Pluf_Cache::factory();
if (null === ($foo=$cache->get('my-key'))) {
$foo = run_complex_operation();
$cache->set('my-key', $foo);
}
return $foo;
In your configuration file, you define the cache engine and its parameters together with the default timeout of the cache in seconds.
$cfg['cache_engine'] = 'Pluf_Cache_File';
$cfg['cache_timeout'] = 300;
Pluf_Cache_File engineThe only configuration variable that is mandatory is:
$cfg['cache_file_folder'] = '/path/to/cache';
Pluf_Cache_Memcached engineFrom the memcached website, memcached is:
a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.
To install it on a debian/ubuntu based system simply do:
sudo apt-get install memcached php5-memcache
sudo pico /etc/php5/conf.d/memcache.ini
When editing the memcache.ini file, replace:
; extension=memcache.so
with:
extension=memcache.so
Then restart Apache or your fastcgi process.
The configuration keys are:
MEMCACHE_COMPRESSED.Pluf_Cache_Apc engineAPC is the Alternative PHP Cache. It is both an opcode cache and an in memory variable store. You need to have it installed and configured to use it.
The configuration keys are:
The compression is done a the php level using the gzinflate/gzdeflate functions.
To get a variable from the cache you need to create a cache object and
get the variable with the get method.
$cache = Pluf_Cache::factory();
$foo = $cache->get('my-key', null);
The get methods has for second parameter the default value to return
if the key is not found in the cache. The default value is null.
To set a variable in the cache, you of course use the set method:
$cache = Pluf_Cache::factory();
$cache->set('my-key', $foo, 300);
The third parameter is the timeout for the key in seconds. The timeout
is optional and if not defined, the cache_timeout configuration
variable is used.
Note: An object can be stored in cache only if it can be
serialized and unserialized using the
(un)serialize functions of PHP.
Report issues in the documentation
If you find errors or issues in the documentation, report a bug. We will update the documentation accordingly.
Pluf © 2005-2008 Loïc d'Anterroches, supported by Céondo Ltd.