ArrayCache.php 961 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Symfony\Component\Cache\Tests\Fixtures;
  3. use Doctrine\Common\Cache\CacheProvider;
  4. class ArrayCache extends CacheProvider
  5. {
  6. private $data = [];
  7. protected function doFetch($id)
  8. {
  9. return $this->doContains($id) ? $this->data[$id][0] : false;
  10. }
  11. protected function doContains($id)
  12. {
  13. if (!isset($this->data[$id])) {
  14. return false;
  15. }
  16. $expiry = $this->data[$id][1];
  17. return !$expiry || time() < $expiry || !$this->doDelete($id);
  18. }
  19. protected function doSave($id, $data, $lifeTime = 0)
  20. {
  21. $this->data[$id] = [$data, $lifeTime ? time() + $lifeTime : false];
  22. return true;
  23. }
  24. protected function doDelete($id)
  25. {
  26. unset($this->data[$id]);
  27. return true;
  28. }
  29. protected function doFlush()
  30. {
  31. $this->data = [];
  32. return true;
  33. }
  34. protected function doGetStats()
  35. {
  36. return null;
  37. }
  38. }