FileCacheInterface.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Drupal\Component\FileCache;
  3. /**
  4. * Interface for objects that allow caching file data.
  5. *
  6. * Parsing YAML, annotations or similar data out of files can be a
  7. * time-consuming process, especially since those files usually don't change
  8. * and identical data is parsed over and over again.
  9. *
  10. * File cache is a self-contained caching layer for such processing, that relies
  11. * on the file modification to ensure that cached data is still up to date and
  12. * does not need to be invalidated externally.
  13. */
  14. interface FileCacheInterface {
  15. /**
  16. * Gets data based on a filename.
  17. *
  18. * @param string $filepath
  19. * Path of the file that the cached data is based on.
  20. *
  21. * @return mixed|null
  22. * The data that was persisted with set() or NULL if there is no data
  23. * or the file has been modified.
  24. */
  25. public function get($filepath);
  26. /**
  27. * Gets data based on filenames.
  28. *
  29. * @param string[] $filepaths
  30. * List of file paths used as cache identifiers.
  31. *
  32. * @return array
  33. * List of cached data keyed by the passed in file paths.
  34. */
  35. public function getMultiple(array $filepaths);
  36. /**
  37. * Stores data based on a filename.
  38. *
  39. * @param string $filepath
  40. * Path of the file that the cached data is based on.
  41. * @param mixed $data
  42. * The data that should be cached.
  43. */
  44. public function set($filepath, $data);
  45. /**
  46. * Deletes data from the cache.
  47. *
  48. * @param string $filepath
  49. * Path of the file that the cached data is based on.
  50. */
  51. public function delete($filepath);
  52. }