Cache.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace Doctrine\Common\Cache;
  3. /**
  4. * Interface for cache drivers.
  5. *
  6. * @link www.doctrine-project.org
  7. */
  8. interface Cache
  9. {
  10. public const STATS_HITS = 'hits';
  11. public const STATS_MISSES = 'misses';
  12. public const STATS_UPTIME = 'uptime';
  13. public const STATS_MEMORY_USAGE = 'memory_usage';
  14. public const STATS_MEMORY_AVAILABLE = 'memory_available';
  15. /**
  16. * Only for backward compatibility (may be removed in next major release)
  17. *
  18. * @deprecated
  19. */
  20. public const STATS_MEMORY_AVAILIABLE = 'memory_available';
  21. /**
  22. * Fetches an entry from the cache.
  23. *
  24. * @param string $id The id of the cache entry to fetch.
  25. *
  26. * @return mixed The cached data or FALSE, if no cache entry exists for the given id.
  27. */
  28. public function fetch($id);
  29. /**
  30. * Tests if an entry exists in the cache.
  31. *
  32. * @param string $id The cache id of the entry to check for.
  33. *
  34. * @return bool TRUE if a cache entry exists for the given cache id, FALSE otherwise.
  35. */
  36. public function contains($id);
  37. /**
  38. * Puts data into the cache.
  39. *
  40. * If a cache entry with the given id already exists, its data will be replaced.
  41. *
  42. * @param string $id The cache id.
  43. * @param mixed $data The cache entry/data.
  44. * @param int $lifeTime The lifetime in number of seconds for this cache entry.
  45. * If zero (the default), the entry never expires (although it may be deleted from the cache
  46. * to make place for other entries).
  47. *
  48. * @return bool TRUE if the entry was successfully stored in the cache, FALSE otherwise.
  49. */
  50. public function save($id, $data, $lifeTime = 0);
  51. /**
  52. * Deletes a cache entry.
  53. *
  54. * @param string $id The cache id.
  55. *
  56. * @return bool TRUE if the cache entry was successfully deleted, FALSE otherwise.
  57. * Deleting a non-existing entry is considered successful.
  58. */
  59. public function delete($id);
  60. /**
  61. * Retrieves cached information from the data store.
  62. *
  63. * The server's statistics array has the following values:
  64. *
  65. * - <b>hits</b>
  66. * Number of keys that have been requested and found present.
  67. *
  68. * - <b>misses</b>
  69. * Number of items that have been requested and not found.
  70. *
  71. * - <b>uptime</b>
  72. * Time that the server is running.
  73. *
  74. * - <b>memory_usage</b>
  75. * Memory used by this server to store items.
  76. *
  77. * - <b>memory_available</b>
  78. * Memory allowed to use for storage.
  79. *
  80. * @return array|null An associative array with server's statistics if available, NULL otherwise.
  81. */
  82. public function getStats();
  83. }