Cache.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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\Common\Cache;
  20. /**
  21. * Interface for cache drivers.
  22. *
  23. * @link www.doctrine-project.org
  24. * @since 2.0
  25. * @author Benjamin Eberlei <kontakt@beberlei.de>
  26. * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
  27. * @author Jonathan Wage <jonwage@gmail.com>
  28. * @author Roman Borschel <roman@code-factory.org>
  29. * @author Fabio B. Silva <fabio.bat.silva@gmail.com>
  30. * @author Kévin Dunglas <dunglas@gmail.com>
  31. */
  32. interface Cache
  33. {
  34. const STATS_HITS = 'hits';
  35. const STATS_MISSES = 'misses';
  36. const STATS_UPTIME = 'uptime';
  37. const STATS_MEMORY_USAGE = 'memory_usage';
  38. const STATS_MEMORY_AVAILABLE = 'memory_available';
  39. /**
  40. * Only for backward compatibility (may be removed in next major release)
  41. *
  42. * @deprecated
  43. */
  44. const STATS_MEMORY_AVAILIABLE = 'memory_available';
  45. /**
  46. * Fetches an entry from the cache.
  47. *
  48. * @param string $id The id of the cache entry to fetch.
  49. *
  50. * @return mixed The cached data or FALSE, if no cache entry exists for the given id.
  51. */
  52. public function fetch($id);
  53. /**
  54. * Tests if an entry exists in the cache.
  55. *
  56. * @param string $id The cache id of the entry to check for.
  57. *
  58. * @return boolean TRUE if a cache entry exists for the given cache id, FALSE otherwise.
  59. */
  60. public function contains($id);
  61. /**
  62. * Puts data into the cache.
  63. *
  64. * If a cache entry with the given id already exists, its data will be replaced.
  65. *
  66. * @param string $id The cache id.
  67. * @param mixed $data The cache entry/data.
  68. * @param int $lifeTime The lifetime in number of seconds for this cache entry.
  69. * If zero (the default), the entry never expires (although it may be deleted from the cache
  70. * to make place for other entries).
  71. *
  72. * @return boolean TRUE if the entry was successfully stored in the cache, FALSE otherwise.
  73. */
  74. public function save($id, $data, $lifeTime = 0);
  75. /**
  76. * Deletes a cache entry.
  77. *
  78. * @param string $id The cache id.
  79. *
  80. * @return boolean TRUE if the cache entry was successfully deleted, FALSE otherwise.
  81. * Deleting a non-existing entry is considered successful.
  82. */
  83. public function delete($id);
  84. /**
  85. * Retrieves cached information from the data store.
  86. *
  87. * The server's statistics array has the following values:
  88. *
  89. * - <b>hits</b>
  90. * Number of keys that have been requested and found present.
  91. *
  92. * - <b>misses</b>
  93. * Number of items that have been requested and not found.
  94. *
  95. * - <b>uptime</b>
  96. * Time that the server is running.
  97. *
  98. * - <b>memory_usage</b>
  99. * Memory used by this server to store items.
  100. *
  101. * - <b>memory_available</b>
  102. * Memory allowed to use for storage.
  103. *
  104. * @since 2.2
  105. *
  106. * @return array|null An associative array with server's statistics if available, NULL otherwise.
  107. */
  108. public function getStats();
  109. }