YacCache.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace ACES\Common\cache;
  3. use ACES\TDEClient;
  4. class YacCache extends iCache
  5. {
  6. private $isEnable = false;
  7. private $yac;
  8. function __construct()
  9. {
  10. if (extension_loaded("yac") && ini_get('yac.enable')==1){
  11. $this->isEnable = true;
  12. $this->yac = new \Yac(self::$CACHE_PREFIX);
  13. }
  14. }
  15. public function get($key)
  16. {
  17. if($this->isEnable){
  18. $key = md5($key);
  19. return $this->yac->get($key);
  20. }
  21. }
  22. /**
  23. * @param $key
  24. * @param $var TDEClient
  25. */
  26. public function set($key,$var)
  27. {
  28. if($this->isEnable){
  29. if (!$var && !$var->checkNullParam()) {
  30. $key = md5($key);
  31. $this->yac->set($key, $var, self::$CACHE_TTL);
  32. }
  33. }
  34. }
  35. public function cacheable()
  36. {
  37. return $this->isEnable;
  38. }
  39. public function delete($key)
  40. {
  41. if($this->isEnable){
  42. $key = md5($key);
  43. return $this->yac->delete($key);
  44. }
  45. }
  46. }