ItemInterface.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Contracts\Cache;
  11. use Psr\Cache\CacheException;
  12. use Psr\Cache\CacheItemInterface;
  13. use Psr\Cache\InvalidArgumentException;
  14. /**
  15. * Augments PSR-6's CacheItemInterface with support for tags and metadata.
  16. *
  17. * @author Nicolas Grekas <p@tchwork.com>
  18. */
  19. interface ItemInterface extends CacheItemInterface
  20. {
  21. /**
  22. * References the Unix timestamp stating when the item will expire.
  23. */
  24. const METADATA_EXPIRY = 'expiry';
  25. /**
  26. * References the time the item took to be created, in milliseconds.
  27. */
  28. const METADATA_CTIME = 'ctime';
  29. /**
  30. * References the list of tags that were assigned to the item, as string[].
  31. */
  32. const METADATA_TAGS = 'tags';
  33. /**
  34. * Adds a tag to a cache item.
  35. *
  36. * Tags are strings that follow the same validation rules as keys.
  37. *
  38. * @param string|string[] $tags A tag or array of tags
  39. *
  40. * @return $this
  41. *
  42. * @throws InvalidArgumentException When $tag is not valid
  43. * @throws CacheException When the item comes from a pool that is not tag-aware
  44. */
  45. public function tag($tags): self;
  46. /**
  47. * Returns a list of metadata info that were saved alongside with the cached value.
  48. *
  49. * See ItemInterface::METADATA_* consts for keys potentially found in the returned array.
  50. */
  51. public function getMetadata(): array;
  52. }