FIRLocalCacheSettings.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Copyright 2023 Google LLC
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. NS_ASSUME_NONNULL_BEGIN
  18. /**
  19. * Marker protocol implemented by all supported cache settings.
  20. *
  21. * The two cache types supported are `PersistentCacheSettings` and `MemoryCacheSettings`. Custom
  22. * implementation is not supported.
  23. */
  24. NS_SWIFT_NAME(LocalCacheSettings)
  25. @protocol FIRLocalCacheSettings
  26. @end
  27. /**
  28. * Configures the SDK to use a persistent cache. Firestore documents and mutations are persisted
  29. * across App restart.
  30. *
  31. * This is the default cache type unless explicitly specified otherwise.
  32. *
  33. * To use, create an instance using one of the initializers, then set the instance to
  34. * `FirestoreSettings.cacheSettings`, and use `FirestoreSettings` instance to configure Firestore
  35. * SDK.
  36. */
  37. NS_SWIFT_NAME(PersistentCacheSettings)
  38. @interface FIRPersistentCacheSettings : NSObject <NSCopying, FIRLocalCacheSettings>
  39. /**
  40. * Creates `PersistentCacheSettings` with default cache size: 100MB.
  41. *
  42. * The cache size is not a hard limit, but a target for the SDK's gabarge collector to work towards.
  43. */
  44. - (instancetype)init;
  45. /**
  46. * Creates `PersistentCacheSettings` with a custom cache size in bytes.
  47. *
  48. * The cache size is not a hard limit, but a target for the SDK's gabarge collector to work towards.
  49. */
  50. - (instancetype)initWithSizeBytes:(NSNumber *)size;
  51. @end
  52. /**
  53. * Marker protocol implemented by all supported garbage collector settings.
  54. *
  55. * The two cache types supported are `MemoryEagerGCSettings` and `MemoryLRUGCSettings`. Custom
  56. * implementation is not supported.
  57. */
  58. NS_SWIFT_NAME(MemoryGarbageCollectorSettings)
  59. @protocol FIRMemoryGarbageCollectorSettings
  60. @end
  61. /**
  62. * Configures the SDK to use an eager garbage collector for memory cache.
  63. *
  64. * Once configured, the SDK will remove any Firestore documents from memory as soon as they are not
  65. * used by any active queries.
  66. *
  67. * To use, create an instance using the initializer, then initialize
  68. * `MemoryCacheSettings` with this instance. This is the default garbage collector, so alternatively
  69. * you can use the default initializer of `MemoryCacheSettings`.
  70. */
  71. NS_SWIFT_NAME(MemoryEagerGCSetting)
  72. @interface FIRMemoryEagerGCSettings : NSObject <NSCopying, FIRMemoryGarbageCollectorSettings>
  73. /**
  74. * Creates an instance of `MemoryEagerGCSettings`.
  75. */
  76. - (instancetype)init;
  77. @end
  78. /**
  79. * Configures the SDK to use a least-recently-used garbage collector for memory cache.
  80. *
  81. * Once configured, the SDK will attempt to remove documents that are least recently used in
  82. * batches, if the current cache size is larger than the given target cache size. Default cache size
  83. * is 100MB.
  84. *
  85. * To use, create an instance using one of the initializers, then initialize
  86. * `MemoryCacheSettings` with this instance.
  87. */
  88. NS_SWIFT_NAME(MemoryLRUGCSettings)
  89. @interface FIRMemoryLRUGCSettings : NSObject <NSCopying, FIRMemoryGarbageCollectorSettings>
  90. /**
  91. * Creates an instance of `FIRMemoryLRUGCSettings`, with default target cache size 100MB. The SDK
  92. * will run garbage collection if the current cache size is larger than 100MB.
  93. */
  94. - (instancetype)init;
  95. /**
  96. * Creates an instance of `FIRMemoryLRUGCSettings`, with a custom target cache size. The SDK will
  97. * run garbage collection if the current cache size is larger than the given size.
  98. */
  99. - (instancetype)initWithSizeBytes:(NSNumber *)size;
  100. @end
  101. /**
  102. * Configures the SDK to use a memory cache. Firestore documents and mutations are NOT persisted
  103. * across App restart.
  104. *
  105. * To use, create an instance using one of the initializer, then set the instance to
  106. * `FirestoreSettings.cacheSettings`, and use `FirestoreSettings` instance to configure Firestore
  107. * SDK.
  108. */
  109. NS_SWIFT_NAME(MemoryCacheSettings)
  110. @interface FIRMemoryCacheSettings : NSObject <NSCopying, FIRLocalCacheSettings>
  111. /**
  112. * Creates an instance of `MemoryCacheSettings`.
  113. */
  114. - (instancetype)init;
  115. /**
  116. * Creates an instance of `MemoryCacheSettings` with given `MemoryGarbageCollectorSettings` to
  117. * custom the gabarge collector.
  118. */
  119. - (instancetype)initWithGarbageCollectorSettings:
  120. (id<FIRMemoryGarbageCollectorSettings, NSObject>)settings;
  121. @end
  122. NS_ASSUME_NONNULL_END