[ Index ]

PHP Cross Reference of Akelos Framework

title

Body

[close]

/ -> AkCache.php (summary)

(no description)

Author: Bermi Ferrer
Copyright: Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org
License: GNU Lesser General Public License
File Size: 344 lines (12 kb)
Included or required: 3 times
Referenced: 0 times
Includes or requires: 4 files
 AkCache/AkMemcache.php
 AkObject.php
 Ak.php
 AkCache/AkAdodbCache.php

Defines 1 class

AkCache:: (7 methods):
  lookupStore()
  expandCacheKey()
  init()
  get()
  save()
  remove()
  clean()


Class: AkCache  - X-Ref

Easy to use class for caching data using a database as
container or the file system.

Akelos Framework provides an easy to use functionality for
caching data using a database as container or the file
system.

By default the cache container is defined in the following
line

<code>define ('AK_CACHE_HANDLER', 1);</code>

in the ''config/config.php'' file

Possible values are:

- 0: No cache at all
- 1: File based cache using the folder defined at AK_CACHE_DIR or the system /tmp dir
- 2: Database based cache. This one has a performance penalty, but works on most servers

Here is a small code spinet of how this works.
<code>
// First we include the cache class and
// create a cache instance
include_once(AK_LIB_DIR.'/AkCache.php');
$Cache =& new AkCache();

// Now we define some details for this cache
$seconds = 3600; // seconds of life for this cache
$cache_id = 'unique identifier for accesing this cache element';

// Now we call the $Cache constructor (ALA AkFramework)
$Cache->init($seconds);

// If the data is not cached, we catch it now
// if it was on cache, $data will hold its content
if (!$data = $Cache->get($cache_id)) {
$data = some_heavy_function_that_takes_too_many_time_or_resources();
$Cache->save($data);
}

// Now you can use data no matter from where did it came from
echo $data;
</code>

This class uses the
[http://pear.php.net/manual/en/package.caching.cache-lite.php
pear Cache_Lite] as driver for file based cache.
In fact you can access an instance of Cache_Lite by
accesing $Cache->_driverInstance.

lookupStore($options = null)   X-Ref
Instantiates and configures the AkCache store.

If $options == NULL the configuration will be taken from the constants:

AK_CACHE_HANDLER and AK_CACHE_OPTIONS

if $options is of type string/int the $options parameter will be considered
as the AK_CACHE_HANDLER_* Type (AK_CACHE_HANDLER_PEAR,AK_CACHE_HANDLER_ADODB,AK_CACHE_HANDLER_MEMCACHE)

if $options is an array of format:

array('file'=>array('cacheDir'=>'/tmp'))

or

array(AK_CACHE_HANDLER_PEAR=>array('cacheDir'=>'/tmp'))

the first key will be used as the AK_CACHE_HANDLER_* Type
and the array as the config options

Default behaviour is calling the method with the $options == null parameter:

AkCache::lookupStore()

Calling it with:

AkCache::lookupStore(true)

will return the configured $cache_store

param: mixed $options
return: mixed   false if no cache could be configured or AkCache instance

expandCacheKey($key, $namespace = null)   X-Ref
No description

init($options = null, $cache_type = null)   X-Ref
Class constructor (ALA Akelos Framework)

This method loads an instance of selected driver in order to
use it class wide.

param: mixed    $options    You can pass a number specifying the second for
param: integer    $cache_type    The default value is set by defining the constant AK_CACHE_HANDLER in the following line
return: void

get($id, $group = 'default')   X-Ref
Test if a cache is available and (if yes) return it

param: string    $id    Cache id
param: string    $group    Name of the cache group.
return: mixed Data of the cache (or false if no cache available)

save($data, $id = null, $group = 'default')   X-Ref
Save some data in the cache

param: string    $data    Data to put in cache
param: string    $id    Cache id
param: string    $group    Name of the cache group
return: boolean True if no problem

remove($id, $group = 'default')   X-Ref
Remove a cache item

param: string    $id    Cache id
param: string    $group    Name of the cache group
return: boolean True if no problem

clean($group = false, $mode = 'ingroup')   X-Ref
Clean the cache

If no group is specified all cache items will be destroyed
else only cache items of the specified group will be
destroyed

param: string    $group    Name of the cache group.
param: string    $mode    Flush cache mode. Options are:
return: boolean True if no problem



Generated: Mon Oct 27 12:43:49 2008 Cross-referenced by PHPXref 0.6