1
0

ICache.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. * @since 30.0.0
  17. */
  18. public const DEFAULT_TTL = 24 * 60 * 60;
  19. /**
  20. * Get a value from the user cache
  21. * @param string $key
  22. * @return mixed
  23. * @since 6.0.0
  24. */
  25. public function get($key);
  26. /**
  27. * Set a value in the user cache
  28. * @param string $key
  29. * @param mixed $value
  30. * @param int $ttl Time To Live in seconds. Defaults to 60*60*24
  31. * @return bool
  32. * @since 6.0.0
  33. */
  34. public function set($key, $value, $ttl = 0);
  35. /**
  36. * Check if a value is set in the user cache
  37. * @param string $key
  38. * @return bool
  39. * @since 6.0.0
  40. * @deprecated 9.1.0 Directly read from GET to prevent race conditions
  41. */
  42. public function hasKey($key);
  43. /**
  44. * Remove an item from the user cache
  45. * @param string $key
  46. * @return bool
  47. * @since 6.0.0
  48. */
  49. public function remove($key);
  50. /**
  51. * Clear the user cache of all entries starting with a prefix
  52. * @param string $prefix (optional)
  53. * @return bool
  54. * @since 6.0.0
  55. */
  56. public function clear($prefix = '');
  57. /**
  58. * Check if the cache implementation is available
  59. * @since 24.0.0
  60. */
  61. public static function isAvailable(): bool;
  62. }