Cache.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace Biz\Cache;
  3. use phpFastCache\Helper\Psr16Adapter;
  4. class Cache
  5. {
  6. private $_cache;
  7. public function __construct()
  8. {
  9. $this->_cache = $this->_load();
  10. }
  11. private function _load()
  12. {
  13. if (!file_exists(ROOT_PATH . '/Config/Cache.php')) {
  14. throw new \Exception("Cache Configuration no exists!");
  15. }
  16. $config = require_once ROOT_PATH . '/Config/Cache.php';
  17. $cacheType = $config['type'];
  18. unset($config['type']);
  19. return new Psr16Adapter($cacheType, $config);
  20. }
  21. private function checkCacheObj(){
  22. if(!$this->_cache){
  23. return 0;
  24. }
  25. return 1;
  26. }
  27. public function get($key, $default = null)
  28. {
  29. return $this->_cache->get($key,$default);
  30. }
  31. public function set($key, $value, $ttl = null)
  32. {
  33. return $this->_cache->set($key, $value,$ttl);
  34. }
  35. public function delete($key)
  36. {
  37. return $this->_cache->delete($key);
  38. }
  39. public function clear()
  40. {
  41. return $this->_cache->clear();
  42. }
  43. public function getMultiple($keys, $default = null)
  44. {
  45. return $this->_cache->getMultiple($keys, $default);
  46. }
  47. public function setMultiple($values, $ttl = null)
  48. {
  49. return $this->_cache->setMultiple($values, $ttl);
  50. }
  51. public function deleteMultiple($keys)
  52. {
  53. return $this->_cache->deleteMultiple($keys);
  54. }
  55. public function has($key)
  56. {
  57. return $this->_cache->has($key);
  58. }
  59. }