Skip to content

Commit f2194c8

Browse files
authored
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
1 parent e700a8f commit f2194c8

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

Firestore/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 10.11.0
22
- [feature] Expose MultiDb API for public preview. (#10465)
33
- [fixed] Fixed a compilation warning related to integer casting. (#11332)
4+
- [fixed] Allow initializing FIRLocalCacheSettings with unlimited size. (#11405)
45

56
# 10.9.0
67
- [feature] Add new cache config API to customize SDK cache settings.

Firestore/Example/Tests/Integration/API/FIRDatabaseTests.mm

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828
#import "Firestore/Source/API/FIRLocalCacheSettings+Internal.h"
2929

3030
#include "Firestore/core/src/api/query_snapshot.h"
31+
#include "Firestore/core/src/api/settings.h"
3132
#include "Firestore/core/src/core/firestore_client.h"
3233
#include "Firestore/core/src/model/database_id.h"
3334
#include "Firestore/core/src/util/string_apple.h"
3435
#include "Firestore/core/test/unit/testutil/app_testing.h"
3536

37+
using api::Settings;
3638
using firebase::firestore::model::DatabaseId;
3739
using firebase::firestore::testutil::AppForUnitTesting;
3840
using firebase::firestore::util::MakeNSString;
@@ -1813,4 +1815,18 @@ - (void)testMinimumCacheSize {
18131815
NSException);
18141816
}
18151817

1818+
- (void)testUnlimitedCacheSize {
1819+
FIRPersistentCacheSettings *cacheSettings =
1820+
[[FIRPersistentCacheSettings alloc] initWithSizeBytes:@(Settings::CacheSizeUnlimited)];
1821+
XCTAssertEqual(cacheSettings.internalSettings.size_bytes(), Settings::CacheSizeUnlimited);
1822+
1823+
self.db.settings.cacheSettings = cacheSettings;
1824+
1825+
FIRDocumentReference *doc = [self.db documentWithPath:@"rooms/eros"];
1826+
NSDictionary<NSString *, id> *data = @{@"value" : @"foo"};
1827+
[self writeDocumentRef:doc data:data];
1828+
FIRDocumentSnapshot *result = [self readDocumentForRef:doc];
1829+
XCTAssertEqualObjects(result.data, data);
1830+
}
1831+
18161832
@end

Firestore/Source/API/FIRLocalCacheSettings.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ - (instancetype)init {
7373

7474
- (instancetype)initWithSizeBytes:(NSNumber *)size {
7575
self = [super init];
76-
if (size.longLongValue < Settings::MinimumCacheSizeBytes) {
76+
if (size.longLongValue != Settings::CacheSizeUnlimited &&
77+
size.longLongValue < Settings::MinimumCacheSizeBytes) {
7778
ThrowInvalidArgument("Cache size must be set to at least %s bytes",
7879
Settings::MinimumCacheSizeBytes);
7980
}

0 commit comments

Comments
 (0)