DoctrineProvider.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Cache;
  11. use Doctrine\Common\Cache\CacheProvider;
  12. use Psr\Cache\CacheItemPoolInterface;
  13. /**
  14. * @author Nicolas Grekas <p@tchwork.com>
  15. */
  16. class DoctrineProvider extends CacheProvider implements PruneableInterface, ResettableInterface
  17. {
  18. private $pool;
  19. public function __construct(CacheItemPoolInterface $pool)
  20. {
  21. $this->pool = $pool;
  22. }
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public function prune()
  27. {
  28. return $this->pool instanceof PruneableInterface && $this->pool->prune();
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function reset()
  34. {
  35. if ($this->pool instanceof ResettableInterface) {
  36. $this->pool->reset();
  37. }
  38. $this->setNamespace($this->getNamespace());
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. protected function doFetch($id)
  44. {
  45. $item = $this->pool->getItem(rawurlencode($id));
  46. return $item->isHit() ? $item->get() : false;
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. protected function doContains($id)
  52. {
  53. return $this->pool->hasItem(rawurlencode($id));
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. protected function doSave($id, $data, $lifeTime = 0)
  59. {
  60. $item = $this->pool->getItem(rawurlencode($id));
  61. if (0 < $lifeTime) {
  62. $item->expiresAfter($lifeTime);
  63. }
  64. return $this->pool->save($item->set($data));
  65. }
  66. /**
  67. * {@inheritdoc}
  68. */
  69. protected function doDelete($id)
  70. {
  71. return $this->pool->deleteItem(rawurlencode($id));
  72. }
  73. /**
  74. * {@inheritdoc}
  75. */
  76. protected function doFlush()
  77. {
  78. $this->pool->clear();
  79. }
  80. /**
  81. * {@inheritdoc}
  82. */
  83. protected function doGetStats()
  84. {
  85. }
  86. }