<?php
/* Please see the README and LICENSE files. */
/**
* Facade or API for the caching stuff
*/
class Cache_Subsystem implements System_Subsystem{
protected static $default_controller = self::CONTROLLER_FILE;
/*
* Bitflags used for automagically deciding cache controller for an object
*/
const EXPENSE_COMPUTATION = 1;
const EXPENSE_IO_REMOTE = 2;
const EXPENSE_IO_DB = 4;
const EXPENSE_IO_FILE = 8;
/*
* Flags representing controllers
*/
const CONTROLLER_MEMCACHE = 1;
const CONTROLLER_FILE = 2;
const CONTROLLER_DB = 3;
public static function cache($name,$object,$age,$controller){
$controller = self::controller_factory($controller);
$controller->set($name, $object, $age);
return true;
}
public static function cache_get($name,$controller){
$controller = self::controller_factory($controller);
return $controller->get($name);
}
protected static function controller_factory($controller){
switch($controller){
case self::CONTROLLER_MEMCACHE:
return new Cache_Controller_Memcache();
break;
default:
case self::CONTROLLER_FILE:
return new Cache_Controller_File();
break;
case self::CONTROLLER_DB:
return new Cache_Controller_Db();
break;
}
}
/**
* Pick a controller based on the the fags, and save an object
*
* @param String $name The unique name
* @param Mixed $object The object
* @param int $age The age in seconds
* @param int $flags The bitflags for controller determination
*/
public static function auto_cache($name,$object,$age,$flags=0){
$controller = $flag>0 ? self::pick_controller($flags):self::$default_controller;
self::cache($name,$object,$age,$controller);
}
public static function pick_controller($flags){
# TODO
#
# Use the bitflag consts to pick a correct controller
# Ex, things that are db or file expenses could be memcache candidates
# whereas computation and remote expenses could be file candidates
}
}
?>