IMemcache.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. *
  13. * @since 8.1.0
  14. */
  15. interface IMemcache extends ICache {
  16. /**
  17. * Set a value in the cache if it's not already stored
  18. *
  19. * @param string $key
  20. * @param mixed $value
  21. * @param int $ttl Time To Live in seconds. Defaults to 60*60*24
  22. * @return bool
  23. * @since 8.1.0
  24. */
  25. public function add($key, $value, $ttl = 0);
  26. /**
  27. * Increase a stored number
  28. *
  29. * If no value is stored with the key, it will behave as if a 0 was stored.
  30. * If a non-numeric value is stored, the operation will fail and `false` is returned.
  31. *
  32. * @param string $key
  33. * @param int $step
  34. * @return int | bool
  35. * @since 8.1.0
  36. */
  37. public function inc($key, $step = 1);
  38. /**
  39. * Decrease a stored number
  40. *
  41. * If no value is stored with the key, the operation will fail and `false` is returned.
  42. * If a non-numeric value is stored, the operation will fail and `false` is returned.
  43. *
  44. * @param string $key
  45. * @param int $step
  46. * @return int | bool
  47. * @since 8.1.0
  48. */
  49. public function dec($key, $step = 1);
  50. /**
  51. * Compare and set
  52. *
  53. * Set $key to $new only if it's current value is $new
  54. *
  55. * @param string $key
  56. * @param mixed $old
  57. * @param mixed $new
  58. * @return bool true if the value was successfully set or false if $key wasn't set to $old
  59. * @since 8.1.0
  60. */
  61. public function cas($key, $old, $new);
  62. /**
  63. * Compare and delete
  64. *
  65. * Delete $key if the stored value is equal to $old
  66. *
  67. * @param string $key
  68. * @param mixed $old
  69. * @return bool true if the value was successfully deleted or false if $key wasn't set to $old
  70. * @since 8.1.0
  71. */
  72. public function cad($key, $old);
  73. /**
  74. * Negative compare and delete
  75. *
  76. * Delete $key if the stored value is not equal to $old
  77. *
  78. * @param string $key
  79. * @param mixed $old
  80. * @return bool true if the value was successfully deleted or false if $key was set to $old or is not set
  81. * @since 30.0.0
  82. */
  83. public function ncad(string $key, mixed $old): bool;
  84. }