ICacheFactory.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  6. * SPDX-License-Identifier: AGPL-3.0-only
  7. */
  8. namespace OCP;
  9. /**
  10. * Interface ICacheFactory
  11. *
  12. * @since 7.0.0
  13. */
  14. interface ICacheFactory {
  15. /**
  16. * Check if any memory cache backend is available
  17. *
  18. * @return bool
  19. * @since 7.0.0
  20. */
  21. public function isAvailable(): bool;
  22. /**
  23. * Check if a local memory cache backend is available
  24. *
  25. * @return bool
  26. * @since 14.0.0
  27. */
  28. public function isLocalCacheAvailable(): bool;
  29. /**
  30. * create a cache instance for storing locks
  31. *
  32. * @param string $prefix
  33. * @return IMemcache
  34. * @since 13.0.0
  35. */
  36. public function createLocking(string $prefix = ''): IMemcache;
  37. /**
  38. * create a distributed cache instance
  39. *
  40. * @param string $prefix
  41. * @return ICache
  42. * @since 13.0.0
  43. */
  44. public function createDistributed(string $prefix = ''): ICache;
  45. /**
  46. * create a local cache instance
  47. *
  48. * @param string $prefix
  49. * @return ICache
  50. * @since 13.0.0
  51. */
  52. public function createLocal(string $prefix = ''): ICache;
  53. /**
  54. * Create an in-memory cache instance
  55. *
  56. * Useful for remembering values inside one process. Cache memory is cleared
  57. * when the object is garbage-collected. Implementation may also expire keys
  58. * earlier when the TTL is reached or too much memory is consumed.
  59. *
  60. * Cache keys are local to the cache object. When building two in-memory
  61. * caches, there is no data exchange between the instances.
  62. *
  63. * @param int $capacity maximum number of cache keys
  64. * @return ICache
  65. * @since 28.0.0
  66. */
  67. public function createInMemory(int $capacity = 512): ICache;
  68. }