StoreInterface.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. * @return void
  40. */
  41. public function invalidate(Request $request);
  42. /**
  43. * Locks the cache for a given Request.
  44. *
  45. * @return bool|string true if the lock is acquired, the path to the current lock otherwise
  46. */
  47. public function lock(Request $request): bool|string;
  48. /**
  49. * Releases the lock for the given Request.
  50. *
  51. * @return bool False if the lock file does not exist or cannot be unlocked, true otherwise
  52. */
  53. public function unlock(Request $request): bool;
  54. /**
  55. * Returns whether or not a lock exists.
  56. *
  57. * @return bool true if lock exists, false otherwise
  58. */
  59. public function isLocked(Request $request): bool;
  60. /**
  61. * Purges data for the given URL.
  62. *
  63. * @return bool true if the URL exists and has been purged, false otherwise
  64. */
  65. public function purge(string $url): bool;
  66. /**
  67. * Cleanups storage.
  68. *
  69. * @return void
  70. */
  71. public function cleanup();
  72. }