cache.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. if (empty($type)) $type = C('cache_open') ? 'redis' : 'file';
  21. $type = strtolower($type);
  22. $class = ucwords($type);
  23. if (!class_exists($class)){
  24. import('cache.cache#'.$type);
  25. }
  26. return new $class($args);
  27. }
  28. /**
  29. * 取得实例
  30. *
  31. * @return object
  32. */
  33. public static function getInstance()
  34. {
  35. if(defined('USE_COROUTINE') && USE_COROUTINE && defined('COROUTINE_HOOK_TCP') && COROUTINE_HOOK_TCP)
  36. {
  37. $args = func_get_args();
  38. return CoRedisPool::instance()->get($args);
  39. } else {
  40. $args = func_get_args();
  41. return get_obj_instance(__CLASS__, 'connect', $args);
  42. }
  43. }
  44. }