16
16
17
17
import androidx .annotation .NonNull ;
18
18
19
+ /**
20
+ * Configures the SDK to use a Least-Recently-Used garbage collector for memory cache.
21
+ *
22
+ * <p>To use, create an instance using {@code MemoryLruGcSettings#newBuilder().build()}, then set
23
+ * the instance to {@code MemoryCacheSettings.Builder#setGcSettings}, and use the built {@code
24
+ * MemoryCacheSettings} instance to configure the Firestore SDK.
25
+ */
19
26
public final class MemoryLruGcSettings implements MemoryGarbageCollectorSettings {
20
27
21
28
private long sizeBytes ;
@@ -30,20 +37,43 @@ public MemoryLruGcSettings build() {
30
37
return new MemoryLruGcSettings (sizeBytes );
31
38
}
32
39
33
- public void setSizeBytes (long size ) {
40
+ /**
41
+ * Sets an approximate cache size threshold for the memory cache. If the cache grows beyond this
42
+ * size, Firestore SDK will start removing data that hasn't been recently used. The size is not
43
+ * a guarantee that the cache will stay below that size, only that if the cache exceeds the
44
+ * given size, cleanup will be attempted.
45
+ *
46
+ * <p>A default size of 100MB (100 * 1024 * 1024) is used if unset. The minimum value to set is
47
+ * 1 MB (1024 * 1024).
48
+ *
49
+ * @return this {@code Builder} instance.
50
+ */
51
+ @ NonNull
52
+ public Builder setSizeBytes (long size ) {
34
53
sizeBytes = size ;
54
+ return this ;
35
55
}
36
56
}
37
57
38
58
private MemoryLruGcSettings (long size ) {
39
59
sizeBytes = size ;
40
60
}
41
61
62
+ /** Returns a new instance of {@link MemoryLruGcSettings.Builder} with default configurations. */
42
63
@ NonNull
43
64
public static MemoryLruGcSettings .Builder newBuilder () {
44
65
return new Builder ();
45
66
}
46
67
68
+ /**
69
+ * Returns cache size threshold for the memory cache. If the cache grows beyond this size,
70
+ * Firestore SDK will start removing data that hasn't been recently used. The size is not a
71
+ * guarantee that the cache will stay below that size, only that if the cache exceeds the given
72
+ * size, cleanup will be attempted.
73
+ *
74
+ * <p>By default, memory LRU cache is enabled with a cache size of 100MB (100 * 1024 * 1024). The
75
+ * minimum value is 1 MB (1024 * 1024).
76
+ */
47
77
public long getSizeBytes () {
48
78
return sizeBytes ;
49
79
}
0 commit comments