CacheTagsChecksumInterface.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace Drupal\Core\Cache;
  3. /**
  4. * Provides checksums for cache tag invalidations.
  5. *
  6. * Cache backends can use this to check if any cache tag invalidations happened
  7. * for a stored cache item.
  8. *
  9. * To do so, they can inject the cache_tags.invalidator.checksum service, and
  10. * when a cache item is written, store cache tags together with the current
  11. * checksum, calculated by getCurrentChecksum(). When a cache item is fetched,
  12. * the checksum can be validated with isValid(). The service will return FALSE
  13. * if any of those cache tags were invalidated in the meantime.
  14. *
  15. * @ingroup cache
  16. */
  17. interface CacheTagsChecksumInterface {
  18. /**
  19. * Returns the sum total of validations for a given set of tags.
  20. *
  21. * Called by a backend when storing a cache item.
  22. *
  23. * @param string[] $tags
  24. * Array of cache tags.
  25. *
  26. * @return string
  27. * Cache tag invalidations checksum.
  28. */
  29. public function getCurrentChecksum(array $tags);
  30. /**
  31. * Returns whether the checksum is valid for the given cache tags.
  32. *
  33. * Used when retrieving a cache item in a cache backend, to verify that no
  34. * cache tag based invalidation happened.
  35. *
  36. * @param int $checksum
  37. * The checksum that was stored together with the cache item.
  38. * @param string[] $tags
  39. * The cache tags that were stored together with the cache item.
  40. *
  41. * @return bool
  42. * FALSE if cache tag invalidations happened for the passed in tags since
  43. * the cache item was stored, TRUE otherwise.
  44. */
  45. public function isValid($checksum, array $tags);
  46. /**
  47. * Reset statically cached tags.
  48. *
  49. * This is only used by tests.
  50. */
  51. public function reset();
  52. }