Cache.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. * @param string $id The cache id.
  65. * @param mixed $data The cache entry/data.
  66. * @param int $lifeTime The cache lifetime.
  67. * If != 0, sets a specific lifetime for this cache entry (0 => infinite lifeTime).
  68. *
  69. * @return boolean TRUE if the entry was successfully stored in the cache, FALSE otherwise.
  70. */
  71. public function save($id, $data, $lifeTime = 0);
  72. /**
  73. * Deletes a cache entry.
  74. *
  75. * @param string $id The cache id.
  76. *
  77. * @return boolean TRUE if the cache entry was successfully deleted, FALSE otherwise.
  78. */
  79. public function delete($id);
  80. /**
  81. * Retrieves cached information from the data store.
  82. *
  83. * The server's statistics array has the following values:
  84. *
  85. * - <b>hits</b>
  86. * Number of keys that have been requested and found present.
  87. *
  88. * - <b>misses</b>
  89. * Number of items that have been requested and not found.
  90. *
  91. * - <b>uptime</b>
  92. * Time that the server is running.
  93. *
  94. * - <b>memory_usage</b>
  95. * Memory used by this server to store items.
  96. *
  97. * - <b>memory_available</b>
  98. * Memory allowed to use for storage.
  99. *
  100. * @since 2.2
  101. *
  102. * @return array|null An associative array with server's statistics if available, NULL otherwise.
  103. */
  104. public function getStats();
  105. }