فهرست منبع

Allow initializing FIRLocalCacheSettings with unlimited size. (#11405)

* Allow initializing FIRLocalCacheSettings with unlimited size.

* Add changelog.

* Add test

* Fix bug

* Add import

* Add import

* Exercise db with CacheSizeUnlimited

* Fix
Tom Andersen 2 سال پیش
والد
کامیت
f2194c8a3c

+ 1 - 0
Firestore/CHANGELOG.md

@@ -1,6 +1,7 @@
 # 10.11.0
 - [feature] Expose MultiDb API for public preview. (#10465)
 - [fixed] Fixed a compilation warning related to integer casting. (#11332)
+- [fixed] Allow initializing FIRLocalCacheSettings with unlimited size. (#11405)
 
 # 10.9.0
 - [feature] Add new cache config API to customize SDK cache settings.

+ 16 - 0
Firestore/Example/Tests/Integration/API/FIRDatabaseTests.mm

@@ -28,11 +28,13 @@
 #import "Firestore/Source/API/FIRLocalCacheSettings+Internal.h"
 
 #include "Firestore/core/src/api/query_snapshot.h"
+#include "Firestore/core/src/api/settings.h"
 #include "Firestore/core/src/core/firestore_client.h"
 #include "Firestore/core/src/model/database_id.h"
 #include "Firestore/core/src/util/string_apple.h"
 #include "Firestore/core/test/unit/testutil/app_testing.h"
 
+using api::Settings;
 using firebase::firestore::model::DatabaseId;
 using firebase::firestore::testutil::AppForUnitTesting;
 using firebase::firestore::util::MakeNSString;
@@ -1813,4 +1815,18 @@ using firebase::firestore::util::TimerId;
                           NSException);
 }
 
+- (void)testUnlimitedCacheSize {
+  FIRPersistentCacheSettings *cacheSettings =
+      [[FIRPersistentCacheSettings alloc] initWithSizeBytes:@(Settings::CacheSizeUnlimited)];
+  XCTAssertEqual(cacheSettings.internalSettings.size_bytes(), Settings::CacheSizeUnlimited);
+
+  self.db.settings.cacheSettings = cacheSettings;
+
+  FIRDocumentReference *doc = [self.db documentWithPath:@"rooms/eros"];
+  NSDictionary<NSString *, id> *data = @{@"value" : @"foo"};
+  [self writeDocumentRef:doc data:data];
+  FIRDocumentSnapshot *result = [self readDocumentForRef:doc];
+  XCTAssertEqualObjects(result.data, data);
+}
+
 @end

+ 2 - 1
Firestore/Source/API/FIRLocalCacheSettings.mm

@@ -73,7 +73,8 @@ using firebase::firestore::util::ThrowInvalidArgument;
 
 - (instancetype)initWithSizeBytes:(NSNumber *)size {
   self = [super init];
-  if (size.longLongValue < Settings::MinimumCacheSizeBytes) {
+  if (size.longLongValue != Settings::CacheSizeUnlimited &&
+      size.longLongValue < Settings::MinimumCacheSizeBytes) {
     ThrowInvalidArgument("Cache size must be set to at least %s bytes",
                          Settings::MinimumCacheSizeBytes);
   }