//include_once('config.php');Load the configuration file to obtain the cache type and cache configuration parameters
global $_SC;
self ::$type = $_SC['cachetype'];//Judgment of short value
self::$conf = $_SC['cacheconf'];//Judgment of short value
}
//External call to create cache object
public static function CreateOperation(){
self::getConfig();
try
{
$error = 'Unknown cache type';
if(in_array(self::$type , self::$allowtype))
{
$type = self::$type.'Cache';
self::$obj = new $type;
self::$obj->init(self::$conf);//Connect
}
else
throw new Exception($error);
}
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "n";
exit;
}
return self: :$obj;
}
}
$_SC = array();
$_SC['cachetype'] = 'redis';//mymem
$_SC['cacheconf'] = array();
$cache = cacheFactory::CreateOperation();
$cache->setVal('a',1);
echo ' ';
$a = $cache-> ;getVal('a');
echo ' ';
$cache->delVal('a');
?>
Copy code
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn