Cache.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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;
  20. use Doctrine\ORM\Cache\QueryCache;
  21. use Doctrine\ORM\Cache\Region;
  22. /**
  23. * Provides an API for querying/managing the second level cache regions.
  24. */
  25. interface Cache
  26. {
  27. public const DEFAULT_QUERY_REGION_NAME = 'query_cache_region';
  28. public const DEFAULT_TIMESTAMP_REGION_NAME = 'timestamp_cache_region';
  29. /**
  30. * May read items from the cache, but will not add items.
  31. */
  32. public const MODE_GET = 1;
  33. /**
  34. * Will never read items from the cache,
  35. * but will add items to the cache as it reads them from the database.
  36. */
  37. public const MODE_PUT = 2;
  38. /**
  39. * May read items from the cache, and add items to the cache.
  40. */
  41. public const MODE_NORMAL = 3;
  42. /**
  43. * The query will never read items from the cache,
  44. * but will refresh items to the cache as it reads them from the database.
  45. */
  46. public const MODE_REFRESH = 4;
  47. /**
  48. * @param string $className The entity class.
  49. *
  50. * @return Region|null
  51. */
  52. public function getEntityCacheRegion($className);
  53. /**
  54. * @param string $className The entity class.
  55. * @param string $association The field name that represents the association.
  56. *
  57. * @return Region|null
  58. */
  59. public function getCollectionCacheRegion($className, $association);
  60. /**
  61. * Determine whether the cache contains data for the given entity "instance".
  62. *
  63. * @param string $className The entity class.
  64. * @param mixed $identifier The entity identifier
  65. *
  66. * @return bool true if the underlying cache contains corresponding data; false otherwise.
  67. */
  68. public function containsEntity($className, $identifier);
  69. /**
  70. * Evicts the entity data for a particular entity "instance".
  71. *
  72. * @param string $className The entity class.
  73. * @param mixed $identifier The entity identifier.
  74. *
  75. * @return void
  76. */
  77. public function evictEntity($className, $identifier);
  78. /**
  79. * Evicts all entity data from the given region.
  80. *
  81. * @param string $className The entity metadata.
  82. *
  83. * @return void
  84. */
  85. public function evictEntityRegion($className);
  86. /**
  87. * Evict data from all entity regions.
  88. *
  89. * @return void
  90. */
  91. public function evictEntityRegions();
  92. /**
  93. * Determine whether the cache contains data for the given collection.
  94. *
  95. * @param string $className The entity class.
  96. * @param string $association The field name that represents the association.
  97. * @param mixed $ownerIdentifier The identifier of the owning entity.
  98. *
  99. * @return bool true if the underlying cache contains corresponding data; false otherwise.
  100. */
  101. public function containsCollection($className, $association, $ownerIdentifier);
  102. /**
  103. * Evicts the cache data for the given identified collection instance.
  104. *
  105. * @param string $className The entity class.
  106. * @param string $association The field name that represents the association.
  107. * @param mixed $ownerIdentifier The identifier of the owning entity.
  108. *
  109. * @return void
  110. */
  111. public function evictCollection($className, $association, $ownerIdentifier);
  112. /**
  113. * Evicts all entity data from the given region.
  114. *
  115. * @param string $className The entity class.
  116. * @param string $association The field name that represents the association.
  117. *
  118. * @return void
  119. */
  120. public function evictCollectionRegion($className, $association);
  121. /**
  122. * Evict data from all collection regions.
  123. *
  124. * @return void
  125. */
  126. public function evictCollectionRegions();
  127. /**
  128. * Determine whether the cache contains data for the given query.
  129. *
  130. * @param string $regionName The cache name given to the query.
  131. *
  132. * @return bool true if the underlying cache contains corresponding data; false otherwise.
  133. */
  134. public function containsQuery($regionName);
  135. /**
  136. * Evicts all cached query results under the given name, or default query cache if the region name is NULL.
  137. *
  138. * @param string|null $regionName The cache name associated to the queries being cached.
  139. */
  140. public function evictQueryRegion($regionName = null);
  141. /**
  142. * Evict data from all query regions.
  143. *
  144. * @return void
  145. */
  146. public function evictQueryRegions();
  147. /**
  148. * Get query cache by region name or create a new one if none exist.
  149. *
  150. * @param string|null $regionName Query cache region name, or default query cache if the region name is NULL.
  151. *
  152. * @return QueryCache The Query Cache associated with the region name.
  153. */
  154. public function getQueryCache($regionName = null);
  155. }