Cache.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. */
  31. interface Cache
  32. {
  33. const STATS_HITS = 'hits';
  34. const STATS_MISSES = 'misses';
  35. const STATS_UPTIME = 'uptime';
  36. const STATS_MEMORY_USAGE = 'memory_usage';
  37. const STATS_MEMORY_AVAILABLE = 'memory_available';
  38. /**
  39. * Only for backward compatibility (may be removed in next major release)
  40. *
  41. * @deprecated
  42. */
  43. const STATS_MEMORY_AVAILIABLE = 'memory_available';
  44. /**
  45. * Fetches an entry from the cache.
  46. *
  47. * @param string $id The id of the cache entry to fetch.
  48. *
  49. * @return mixed The cached data or FALSE, if no cache entry exists for the given id.
  50. */
  51. function fetch($id);
  52. /**
  53. * Tests if an entry exists in the cache.
  54. *
  55. * @param string $id The cache id of the entry to check for.
  56. *
  57. * @return boolean TRUE if a cache entry exists for the given cache id, FALSE otherwise.
  58. */
  59. function contains($id);
  60. /**
  61. * Puts data into the cache.
  62. *
  63. * @param string $id The cache id.
  64. * @param mixed $data The cache entry/data.
  65. * @param int $lifeTime The cache lifetime.
  66. * If != 0, sets a specific lifetime for this cache entry (0 => infinite lifeTime).
  67. *
  68. * @return boolean TRUE if the entry was successfully stored in the cache, FALSE otherwise.
  69. */
  70. function save($id, $data, $lifeTime = 0);
  71. /**
  72. * Deletes a cache entry.
  73. *
  74. * @param string $id The cache id.
  75. *
  76. * @return boolean TRUE if the cache entry was successfully deleted, FALSE otherwise.
  77. */
  78. function delete($id);
  79. /**
  80. * Retrieves cached information from the data store.
  81. *
  82. * The server's statistics array has the following values:
  83. *
  84. * - <b>hits</b>
  85. * Number of keys that have been requested and found present.
  86. *
  87. * - <b>misses</b>
  88. * Number of items that have been requested and not found.
  89. *
  90. * - <b>uptime</b>
  91. * Time that the server is running.
  92. *
  93. * - <b>memory_usage</b>
  94. * Memory used by this server to store items.
  95. *
  96. * - <b>memory_available</b>
  97. * Memory allowed to use for storage.
  98. *
  99. * @since 2.2
  100. *
  101. * @return array|null An associative array with server's statistics if available, NULL otherwise.
  102. */
  103. function getStats();
  104. }