Apcu.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace Qii\Cache;
  3. class Apcu implements Intf
  4. {
  5. const VERSION = '1.2';
  6. public $policy = array('life_time' => 3600);//设置目录、过期时间、文件前缀
  7. public function __construct(array $policy = null)
  8. {
  9. if (!empty($policy)) {
  10. $this->policy = array_merge($this->policy, $policy);
  11. }
  12. }
  13. public function set($key, $value, array $policy = null)
  14. {
  15. if(is_array($policy))
  16. {
  17. $this->policy = array_merge($this->policy, $policy);
  18. }
  19. return apcu_store($key, $value, $this->policy['life_time']);
  20. }
  21. public function get($key)
  22. {
  23. return apcu_fetch($key);
  24. }
  25. public function exists($key)
  26. {
  27. return apcu_exists($key);
  28. }
  29. public function del($key)
  30. {
  31. return apcu_delete($key);
  32. }
  33. public function clean()
  34. {
  35. // TODO: Implement clean() method.
  36. }
  37. public function remove($key)
  38. {
  39. return $this->del($key);
  40. }
  41. }