ICache.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. // use OCP namespace for all classes that are considered public.
  8. // This means that they should be used by apps instead of the internal Nextcloud classes
  9. namespace OCP;
  10. /**
  11. * This interface defines method for accessing the file based user cache.
  12. * @since 6.0.0
  13. */
  14. interface ICache {
  15. /**
  16. * Get a value from the user cache
  17. * @param string $key
  18. * @return mixed
  19. * @since 6.0.0
  20. */
  21. public function get($key);
  22. /**
  23. * Set a value in the user cache
  24. * @param string $key
  25. * @param mixed $value
  26. * @param int $ttl Time To Live in seconds. Defaults to 60*60*24
  27. * @return bool
  28. * @since 6.0.0
  29. */
  30. public function set($key, $value, $ttl = 0);
  31. /**
  32. * Check if a value is set in the user cache
  33. * @param string $key
  34. * @return bool
  35. * @since 6.0.0
  36. * @deprecated 9.1.0 Directly read from GET to prevent race conditions
  37. */
  38. public function hasKey($key);
  39. /**
  40. * Remove an item from the user cache
  41. * @param string $key
  42. * @return bool
  43. * @since 6.0.0
  44. */
  45. public function remove($key);
  46. /**
  47. * Clear the user cache of all entries starting with a prefix
  48. * @param string $prefix (optional)
  49. * @return bool
  50. * @since 6.0.0
  51. */
  52. public function clear($prefix = '');
  53. /**
  54. * Check if the cache implementation is available
  55. * @since 24.0.0
  56. */
  57. public static function isAvailable(): bool;
  58. }