Pool.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace Elgg\Cache;
  3. /**
  4. * Represents a group of key-value pairs whose values can be invalidated,
  5. * forcing a recalculation of the value.
  6. *
  7. * Exactly how/when the values are invalidated is not specified by this API,
  8. * except that specific values can be forcefully invalidated with ::invalidate().
  9. *
  10. * WARNING: API IN FLUX. DO NOT USE DIRECTLY.
  11. *
  12. * @package Elgg
  13. * @subpackage Cache
  14. * @since 1.10.0
  15. *
  16. * @access private
  17. */
  18. interface Pool {
  19. /**
  20. * Fetches a value from the cache, calculating on miss via $callback.
  21. *
  22. * @param string|int $key A plain string ID for the cache entry
  23. * @param callable $callback Logic for calculating the cache entry on miss
  24. *
  25. * @return mixed The cache value
  26. */
  27. public function get($key, callable $callback);
  28. /**
  29. * Forcefully invalidates the value associated with the given key.
  30. *
  31. * Implementations must:
  32. * * Immediately consider the value stale
  33. * * Recalculate the value at the next opportunity
  34. *
  35. * @param string|int $key A plain string ID for the cache entry to invalidate.
  36. *
  37. * @return void
  38. */
  39. public function invalidate($key);
  40. /**
  41. * Prime the cache to a specific value.
  42. *
  43. * This is useful when the value was calculated by some out-of-band means.
  44. * For example, when a list of rows is fetched from the database, you can
  45. * prime the cache for each individual result.
  46. *
  47. * @param string|int $key A plain string ID for the cache entry
  48. * @param mixed $value The cache value
  49. *
  50. * @return void
  51. */
  52. public function put($key, $value);
  53. }