CacheInterface.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php namespace Gregwar\Cache;
  2. interface CacheInterface {
  3. /**
  4. * Sets the cache directory
  5. *
  6. * @param string $cacheDirectory the cache directory
  7. * @return self
  8. */
  9. public function setCacheDirectory($cacheDirectory);
  10. /**
  11. * Gets the cache directory
  12. *
  13. * @return string the cache directory
  14. */
  15. public function getCacheDirectory();
  16. /**
  17. * Sets the actual cache directory
  18. *
  19. * @param string $actualCacheDirectory the actual cache directory
  20. * @return self
  21. */
  22. public function setActualCacheDirectory($actualCacheDirectory = null);
  23. /**
  24. * Returns the actual cache directory
  25. */
  26. public function getActualCacheDirectory();
  27. /**
  28. * Change the prefix size
  29. *
  30. * @param int $prefixSize the size of the prefix directories
  31. * @return self
  32. */
  33. public function setPrefixSize($prefixSize);
  34. /**
  35. * Change the directory mode
  36. *
  37. * @param int $directoryMode the directory mode to use
  38. * @return self
  39. */
  40. public function setDirectoryMode($directoryMode);
  41. /**
  42. * Gets the cache file name
  43. *
  44. * @param string $filename the name of the cache file
  45. * @param bool $actual get the actual file or the public file
  46. * @param bool $mkdir a boolean to enable/disable the construction of the
  47. * cache file directory
  48. * @return string
  49. */
  50. public function getCacheFile($filename, $actual = false, $mkdir = false);
  51. /**
  52. * Checks if the target filename exists in the cache and if the conditions
  53. * are respected
  54. *
  55. * @param string $filename the filename
  56. * @param array $conditions the conditions to respect
  57. * @return bool
  58. */
  59. public function exists($filename, array $conditions = array());
  60. /**
  61. * Alias for exists
  62. *
  63. * @param string $filename the filename
  64. * @param array $conditions the conditions to respect
  65. * @return bool
  66. */
  67. public function check($filename, array $conditions = array());
  68. /**
  69. * Write data in the cache
  70. *
  71. * @param string $filename the name of the cache file
  72. * @param string $contents the contents to store
  73. * @return self
  74. */
  75. public function set($filename, $contents = '');
  76. /**
  77. * Alias for set()
  78. *
  79. * @param string $filename the name of the cache file
  80. * @param string $contents the contents to store
  81. * @return self
  82. */
  83. public function write($filename, $contents = '');
  84. /**
  85. * Get data from the cache
  86. *
  87. * @param string $filename the cache file name
  88. * @param array $conditions
  89. * @return null|string
  90. */
  91. public function get($filename, array $conditions = array());
  92. /**
  93. * Get or create the cache entry
  94. *
  95. * @param string $filename the cache file name
  96. * @param array $conditions an array of conditions about expiration
  97. * @param \Closure $function the closure to call if the file does not exist
  98. * @param bool $file returns the cache file or the file contents
  99. * @param bool $actual returns the actual cache file
  100. * @return string
  101. * @throws \InvalidArgumentException
  102. */
  103. public function getOrCreate($filename, array $conditions = array(), $function, $file = false, $actual = false);
  104. /**
  105. * Alias to getOrCreate with $file = true
  106. *
  107. * @param string $filename the cache file name
  108. * @param array $conditions an array of conditions about expiration
  109. * @param \Closure $function the closure to call if the file does not exist
  110. * @param bool $actual returns the actual cache file
  111. * @return string
  112. * @throws \InvalidArgumentException
  113. */
  114. public function getOrCreateFile($filename, array $conditions = array(), $function, $actual = false);
  115. }