$instance
$instance :
cache.php 缓存工厂类
<?php
namespace ticky;
/**
* cache.php 缓存工厂类
*/
class cache {
public static $instance = null;
public static $driver = null;
public static $config = null;
public static $expire = 0;
private static function getconfig() {
self::$expire = config::get('cache', 'expire');
self::$driver = config::get('cache', 'driver');
self::$config = config::get('cache', self::$driver);
}
/**
* 返回当前终级类对象的实例
* @return object
*/
public static function instance($name = false) {
self::getconfig();
$type = !empty(self::$driver) ? self::$driver : 'file';
if (false === $name) {
$name = md5(serialize(self::$config));
}
if (true === $name || !isset(self::$instance[$name])) {
$class = false === strpos($type, '\\') ? '\\ticky\\cache\\driver\\' . $type : $type;
if (true === $name) {
return new $class(self::$config);
}
self::$instance[$name] = new $class(self::$config);
}
return self::$instance[$name];
}
}