StoreInterface.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * This code is partially based on the Rack-Cache library by Ryan Tomayko,
  8. * which is released under the MIT license.
  9. *
  10. * For the full copyright and license information, please view the LICENSE
  11. * file that was distributed with this source code.
  12. */
  13. namespace Symfony\Component\HttpKernel\HttpCache;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. /**
  17. * Interface implemented by HTTP cache stores.
  18. *
  19. * @author Fabien Potencier <fabien@symfony.com>
  20. */
  21. interface StoreInterface
  22. {
  23. /**
  24. * Locates a cached Response for the Request provided.
  25. */
  26. public function lookup(Request $request): ?Response;
  27. /**
  28. * Writes a cache entry to the store for the given Request and Response.
  29. *
  30. * Existing entries are read and any that match the response are removed. This
  31. * method calls write with the new list of cache entries.
  32. *
  33. * @return string The key under which the response is stored
  34. */
  35. public function write(Request $request, Response $response): string;
  36. /**
  37. * Invalidates all cache entries that match the request.
  38. */
  39. public function invalidate(Request $request): void;
  40. /**
  41. * Locks the cache for a given Request.
  42. *
  43. * @return bool|string true if the lock is acquired, the path to the current lock otherwise
  44. */
  45. public function lock(Request $request): bool|string;
  46. /**
  47. * Releases the lock for the given Request.
  48. *
  49. * @return bool False if the lock file does not exist or cannot be unlocked, true otherwise
  50. */
  51. public function unlock(Request $request): bool;
  52. /**
  53. * Returns whether or not a lock exists.
  54. *
  55. * @return bool true if lock exists, false otherwise
  56. */
  57. public function isLocked(Request $request): bool;
  58. /**
  59. * Purges data for the given URL.
  60. *
  61. * @return bool true if the URL exists and has been purged, false otherwise
  62. */
  63. public function purge(string $url): bool;
  64. /**
  65. * Cleanups storage.
  66. */
  67. public function cleanup(): void;
  68. }