Apcu.php 842 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace Qii\Cache;
  3. class Apcu implements Qii_Cache_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, $policy)
  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. }