RegionsConfiguration.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /*
  3. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. *
  15. * This software consists of voluntary contributions made by many individuals
  16. * and is licensed under the MIT license. For more information, see
  17. * <http://www.doctrine-project.org>.
  18. */
  19. namespace Doctrine\ORM\Cache;
  20. /**
  21. * Cache regions configuration
  22. */
  23. class RegionsConfiguration
  24. {
  25. /** @var array<string,int> */
  26. private $lifetimes = [];
  27. /** @var array<string,int> */
  28. private $lockLifetimes = [];
  29. /** @var int */
  30. private $defaultLifetime;
  31. /** @var int */
  32. private $defaultLockLifetime;
  33. /**
  34. * @param int $defaultLifetime
  35. * @param int $defaultLockLifetime
  36. */
  37. public function __construct($defaultLifetime = 3600, $defaultLockLifetime = 60)
  38. {
  39. $this->defaultLifetime = (int) $defaultLifetime;
  40. $this->defaultLockLifetime = (int) $defaultLockLifetime;
  41. }
  42. /**
  43. * @return int
  44. */
  45. public function getDefaultLifetime()
  46. {
  47. return $this->defaultLifetime;
  48. }
  49. /**
  50. * @param int $defaultLifetime
  51. */
  52. public function setDefaultLifetime($defaultLifetime)
  53. {
  54. $this->defaultLifetime = (int) $defaultLifetime;
  55. }
  56. /**
  57. * @return int
  58. */
  59. public function getDefaultLockLifetime()
  60. {
  61. return $this->defaultLockLifetime;
  62. }
  63. /**
  64. * @param int $defaultLockLifetime
  65. */
  66. public function setDefaultLockLifetime($defaultLockLifetime)
  67. {
  68. $this->defaultLockLifetime = (int) $defaultLockLifetime;
  69. }
  70. /**
  71. * @param string $regionName
  72. *
  73. * @return int
  74. */
  75. public function getLifetime($regionName)
  76. {
  77. return $this->lifetimes[$regionName] ?? $this->defaultLifetime;
  78. }
  79. /**
  80. * @param string $name
  81. * @param int $lifetime
  82. */
  83. public function setLifetime($name, $lifetime)
  84. {
  85. $this->lifetimes[$name] = (int) $lifetime;
  86. }
  87. /**
  88. * @param string $regionName
  89. *
  90. * @return int
  91. */
  92. public function getLockLifetime($regionName)
  93. {
  94. return $this->lockLifetimes[$regionName] ?? $this->defaultLockLifetime;
  95. }
  96. /**
  97. * @param string $name
  98. * @param int $lifetime
  99. */
  100. public function setLockLifetime($name, $lifetime)
  101. {
  102. $this->lockLifetimes[$name] = (int) $lifetime;
  103. }
  104. }