Stash.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace League\Flysystem\Cached\Storage;
  3. use Stash\Pool;
  4. class Stash extends AbstractCache
  5. {
  6. /**
  7. * @var string storage key
  8. */
  9. protected $key;
  10. /**
  11. * @var int|null seconds until cache expiration
  12. */
  13. protected $expire;
  14. /**
  15. * @var \Stash\Pool Stash pool instance
  16. */
  17. protected $pool;
  18. /**
  19. * Constructor.
  20. *
  21. * @param \Stash\Pool $pool
  22. * @param string $key storage key
  23. * @param int|null $expire seconds until cache expiration
  24. */
  25. public function __construct(Pool $pool, $key = 'flysystem', $expire = null)
  26. {
  27. $this->key = $key;
  28. $this->expire = $expire;
  29. $this->pool = $pool;
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function load()
  35. {
  36. $item = $this->pool->getItem($this->key);
  37. $contents = $item->get();
  38. if ($item->isMiss() === false) {
  39. $this->setFromStorage($contents);
  40. }
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function save()
  46. {
  47. $contents = $this->getForStorage();
  48. $item = $this->pool->getItem($this->key);
  49. $item->set($contents, $this->expire);
  50. }
  51. }