<?php
/*
* @package LabCMS
* @copyright (c) 2006 Alexander Levin aka Loki (loki_angel@mail.ru)
* @support http://labcms.ru
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/

class Cache_Generic
{
	private static $_cache=null;
	
	public static function init($type=null)
	{
		if (!$type) $type=config::get('core.use_memcached')?"memcache":"file";
		
		if (self::$_cache[$type]) return self::$_cache[$type];
		
		switch($type)
		{
			case('memcache'):
				$class="Memcache";
				if (!class_exists('Memcache')) {
					return _m('Класс Memcache не найден! Кэширование отключено');
				}
				break;
			case('file'):
				$class="Lab";
				break;
		}
		
		$classname='Cache_'.$class;
		if (empty(self::$_cache[$type])) {
			self::$_cache[$type]=new $classname();
		}
		return self::$_cache[$type];
	}
}