1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
<?php
# Movable Type (r) Open Source (C) 2001-2012 Six Apart, Ltd.
# This program is distributed under the terms of the
# GNU General Public License, version 2.
#
# $Id$
abstract class BaseCache {
protected $_ttl = 0;
public function __construct($ttl = 0) {
$this->_ttl = $ttl;
}
abstract public function get ($key, $ttl = null);
abstract public function get_multi ($keys, $ttl = null);
abstract public function delete ($key);
abstract public function add ($key, $val, $ttl = null);
abstract public function replace ($key, $val, $ttl = null);
abstract public function set ($key, $val, $ttl = null);
abstract public function flush_all();
}
abstract class CacheProviderFactory {
private static $_provider = array(
'session' => 'cachesession',
'memcached' => 'cachememcached',
'memory' => 'cachememory'
);
public static function get_provider($type = 'memory', $ttl = 0) {
if (empty($type))
return null;
if (!array_key_exists($type, self::$_provider)) {
require_once('class.exception.php');
throw new MTException("Can't load cache provider. (" . $type . ")");
}
$name = CacheProviderFactory::$_provider[$type];
require_once("class.$name.php");
$provider = new $name($ttl);
return $provider;
}
public static function add_provider($type, $class) {
if (empty($type) or empty($class))
return false;
CacheProviderFactory::$_provider[$type] = $class;
return true;
}
}
?>
|