traitCache.php 970 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Qii\Driver;
  3. trait traitCache
  4. {
  5. public $cache;
  6. /**
  7. * 设置Cache
  8. *
  9. * @param String $cache
  10. * @param Array $policy
  11. */
  12. final public function setCache($cache, $policy)
  13. {
  14. \Qii\Autoloader\Import::requires(Qii_DIR . DS . 'Qii' . DS . 'Cache.php');
  15. $this->cache = \Qii\Autoloader\Psr4::loadClass('\Qii\Cache', $cache)->initialization($policy);//载入cache类文件
  16. }
  17. /**
  18. * 缓存内容
  19. *
  20. * @param String $id
  21. * @param Array $value
  22. * @return Bool
  23. */
  24. final public function cache($id, $value)
  25. {
  26. return $this->cache->set($id, $value);
  27. }
  28. /**
  29. * 获取缓存的类
  30. */
  31. final public function getCache()
  32. {
  33. return $this->cache;
  34. }
  35. /**
  36. * 获取缓存内容
  37. *
  38. * @param String $id
  39. * @return Array
  40. */
  41. final public function getCacheData($id)
  42. {
  43. return $this->cache->get($id);
  44. }
  45. }