Class AkCache

(line 83)

Description

AkObject
   |
   --AkCache

Located in File: /AkCache.php

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

  1. define ('AK_CACHE_HANDLER'1);

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.
  1.  // First we include the cache class and
  2.  // create a cache instance
  3.  include_once(AK_LIB_DIR.'/AkCache.php');
  4.  $Cache =new AkCache();
  5.  
  6.  // Now we define some details for this cache
  7.  $seconds = 3600// seconds of life for this cache
  8.  $cache_id 'unique identifier for accesing this cache element';
  9.  
  10.  // Now we call the $Cache constructor (ALA AkFramework)
  11.  $Cache->init($seconds);
  12.  
  13.  // If the data is not cached, we catch it now
  14.  // if it was on cache, $data will hold its content
  15.  if (!$data $Cache->get($cache_id)) {
  16.  $data = some_heavy_function_that_takes_too_many_time_or_resources();
  17.  $Cache->save($data);
  18.  }
  19.  
  20.  // Now you can use data no matter from where did it came from
  21.  echo $data;

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.



Class Variables

Summary:
boolean $cache_enabled

$cache_enabled = true (line 100)

Data type : boolean

Ecnables / Disables caching
  • var: - true
  • access: - public

Class Constants

Summary:

Method Detail

Summary:
boolean clean ([string $group = false], [string $mode = 'ingroup'])
mixed get (string $id, [string $group = 'default'])
void init ([mixed $options = null], [integer $cache_type = AK_CACHE_HANDLER])
boolean remove (string $id, [string $group = 'default'])
boolean save (string $data, [string $id = null], [string $group = 'default'])

Method clean (line 244)

boolean clean( [string $group = false], [string $mode = 'ingroup'])

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

Parameters

  • string $group: Name of the cache group. If no group is specified all cache items will be destroyed else only cache items of the specified group will be destroyed
  • string $mode:

    Flush cache mode. Options are:

    • old
    • ingroup
    • notingroup

Info

  • return - True if no problem
  • access - public

Method get (line 190)

mixed get( string $id, [string $group = 'default'])

Test if a cache is available and (if yes) return it

Parameters

  • string $id: Cache id
  • string $group: Name of the cache group.

Info

  • return - Data of the cache (or false if no cache available)
  • access - public

Method init (line 151)

void init( [mixed $options = null], [integer $cache_type = AK_CACHE_HANDLER])

Class constructor (ALA Akelos Framework)

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

Parameters

  • mixed $options:

    You can pass a number specifying the second for the cache to expire or an array with the following options:

    1.  $options = array(
    2.  //This options are valid for both cache contains (database and file based)
    3.  'lifeTime' => cache lifetime in seconds
    4.  (int),
    5.  'memoryCaching' => enable / disable memory caching (boolean),
    6.  'automaticSerialization' => enable / disable automatic serialization (boolean)
    7.  
    8.  //This options are for file based cache
    9.  'cacheDir' => directory where to put the cache files (string),
    10.  'caching' => enable / disable caching (boolean),
    11.  'fileLocking' => enable / disable fileLocking (boolean),
    12.  'writeControl' => enable / disable write control (boolean),
    13.  'readControl' => enable / disable read control (boolean),
    14.  'readControlType' => type of read control
    15.  'crc32''md5''strlen' (string),
    16.  'pearErrorMode' => pear error mode (when raiseError is called(cf PEAR doc(int),
    17.  'onlyMemoryCaching' => enable / disable only memory caching (boolean),
    18.  'memoryCachingLimit' => max nbr of records to store into memory caching (int),
    19.  'fileNameProtection' => enable / disable automatic file name protection (boolean),
    20.  'automaticCleaningFactor' => distable / tune automatic cleaning process (int)
    21.  'hashedDirectoryLevel' => level of the hashed directory system (int)
    22.  );

  • integer $cache_type:

    The default value is set by defining the constant AK_CACHE_HANDLER in the following line

    1. define ('AK_CACHE_HANDLER'1);

    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

Info

  • access - public

Method remove (line 219)

boolean remove( string $id, [string $group = 'default'])

Remove a cache item

Parameters

  • string $id: Cache id
  • string $group: Name of the cache group

Info

  • return - True if no problem
  • access - public

Method save (line 205)

boolean save( string $data, [string $id = null], [string $group = 'default'])

Save some data in the cache

Parameters

  • string $data: Data to put in cache
  • string $id: Cache id
  • string $group: Name of the cache group

Info

  • return - True if no problem
  • access - public

Inherited Variables

Inherited Class Variable Summary

Inherited Methods

Inherited Method Summary

Inherited From Class AkObject

AkObject::AkObject() - A hack to support __construct() on PHP 4

AkObject::__construct() - Class constructor, overriden in descendant classes

AkObject::freeMemory() - Unsets circular reference children that are not freed from memory when calling unset() or when the parent object is garbage collected.

AkObject::log() -

AkObject::toString() - Object-to-string conversion

AkObject::__clone() - Clone class (Zend Engine 2 compatibility trick)

AkObject::__destruct() - Class destructor, overriden in descendant classes

AkObject::__toString() -



Documentation generated on Tue, 17 Jun 2008 14:24:54 +0200 by phpDocumentor 1.3.2