cache.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * 缓存操作
  4. *
  5. */
  6. defined('InShopNC') or exit('Access Invalid!');
  7. class Cache
  8. {
  9. protected $params;
  10. protected $enable;
  11. protected $handler;
  12. /**
  13. * 实例化缓存驱动
  14. *
  15. * @param unknown_type $type
  16. * @param unknown_type $args
  17. * @return unknown
  18. */
  19. public function connect($type,$args = array())
  20. {
  21. if (empty($type)) $type = C('cache_open') ? 'redis' : 'file';
  22. $type = strtolower($type);
  23. $class = ucwords($type);
  24. if (!class_exists($class)){
  25. import('cache.cache#'.$type);
  26. }
  27. return new $class($args);
  28. }
  29. /**
  30. * 取得实例
  31. *
  32. * @return object
  33. */
  34. public static function getInstance()
  35. {
  36. if(defined('USE_COROUTINE') && USE_COROUTINE && defined('COROUTINE_HOOK_TCP') && COROUTINE_HOOK_TCP)
  37. {
  38. $args = func_get_args();
  39. return CoRedisPool::instance()->get($args);
  40. } else {
  41. $args = func_get_args();
  42. return get_obj_instance(__CLASS__, 'connect', $args);
  43. }
  44. }
  45. }