Cache.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /*
  3. * $Id$
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the MIT license. For more information, see
  19. * <http://www.doctrine-project.org>.
  20. */
  21. namespace Doctrine\Common\Cache;
  22. /**
  23. * Interface for cache drivers.
  24. *
  25. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  26. * @link www.doctrine-project.org
  27. * @since 2.0
  28. * @author Benjamin Eberlei <kontakt@beberlei.de>
  29. * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
  30. * @author Jonathan Wage <jonwage@gmail.com>
  31. * @author Roman Borschel <roman@code-factory.org>
  32. * @author Fabio B. Silva <fabio.bat.silva@gmail.com>
  33. */
  34. interface Cache
  35. {
  36. const STATS_HITS = 'hits';
  37. const STATS_MISSES = 'misses';
  38. const STATS_UPTIME = 'uptime';
  39. const STATS_MEMORY_USAGE = 'memory_usage';
  40. const STATS_MEMORY_AVAILIABLE = 'memory_available';
  41. /**
  42. * Fetches an entry from the cache.
  43. *
  44. * @param string $id cache id The id of the cache entry to fetch.
  45. * @return mixed The cached data or FALSE, if no cache entry exists for the given id.
  46. */
  47. function fetch($id);
  48. /**
  49. * Test if an entry exists in the cache.
  50. *
  51. * @param string $id cache id The cache id of the entry to check for.
  52. * @return boolean TRUE if a cache entry exists for the given cache id, FALSE otherwise.
  53. */
  54. function contains($id);
  55. /**
  56. * Puts data into the cache.
  57. *
  58. * @param string $id The cache id.
  59. * @param mixed $data The cache entry/data.
  60. * @param int $lifeTime The lifetime. If != 0, sets a specific lifetime for this cache entry (0 => infinite lifeTime).
  61. * @return boolean TRUE if the entry was successfully stored in the cache, FALSE otherwise.
  62. */
  63. function save($id, $data, $lifeTime = 0);
  64. /**
  65. * Deletes a cache entry.
  66. *
  67. * @param string $id cache id
  68. * @return boolean TRUE if the cache entry was successfully deleted, FALSE otherwise.
  69. */
  70. function delete($id);
  71. /**
  72. * Retrieves cached information from data store
  73. *
  74. * The server's statistics array has the following values:
  75. *
  76. * - <b>hits</b>
  77. * Number of keys that have been requested and found present.
  78. *
  79. * - <b>misses</b>
  80. * Number of items that have been requested and not found.
  81. *
  82. * - <b>uptime</b>
  83. * Time that the server is running.
  84. *
  85. * - <b>memory_usage</b>
  86. * Memory used by this server to store items.
  87. *
  88. * - <b>memory_available</b>
  89. * Memory allowed to use for storage.
  90. *
  91. * @since 2.2
  92. * @var array Associative array with server's statistics if available, NULL otherwise.
  93. */
  94. function getStats();
  95. }