@@ -171,6 +171,8 @@ static void initialize(Configuration configuration, ParsePlugins parsePlugins) {
171171 if (configuration .localDataStoreEnabled ) {
172172 offlineStore = new OfflineStore (configuration .context );
173173 } else {
174+ ParseKeyValueCache .maxKeyValueCacheBytes = configuration .maxKeyValueCacheBytes ;
175+ ParseKeyValueCache .maxKeyValueCacheFiles = configuration .maxKeyValueCacheFiles ;
174176 ParseKeyValueCache .initialize (configuration .context );
175177 }
176178
@@ -582,6 +584,8 @@ public static final class Configuration {
582584 final boolean allowCustomObjectId ;
583585 final OkHttpClient .Builder clientBuilder ;
584586 final int maxRetries ;
587+ final int maxKeyValueCacheBytes ;
588+ final int maxKeyValueCacheFiles ;
585589
586590 private Configuration (Builder builder ) {
587591 this .context = builder .context ;
@@ -592,10 +596,19 @@ private Configuration(Builder builder) {
592596 this .allowCustomObjectId = builder .allowCustomObjectId ;
593597 this .clientBuilder = builder .clientBuilder ;
594598 this .maxRetries = builder .maxRetries ;
599+ this .maxKeyValueCacheBytes = builder .maxKeyValueCacheBytes ;
600+ this .maxKeyValueCacheFiles = builder .maxKeyValueCacheFiles ;
595601 }
596602
597603 /** Allows for simple constructing of a {@code Configuration} object. */
598604 public static final class Builder {
605+ /** The default maximum number of bytes to use for the Parse cache on disk. */
606+ public static final int DEFAULT_MAX_KEY_VALUE_CACHE_BYTES =
607+ ParseKeyValueCache .DEFAULT_MAX_KEY_VALUE_CACHE_BYTES ;
608+ /** The default maximum number of files to store in the Parse cache on disk. */
609+ public static final int DEFAULT_MAX_KEY_VALUE_CACHE_FILES =
610+ ParseKeyValueCache .DEFAULT_MAX_KEY_VALUE_CACHE_FILES ;
611+
599612 private final Context context ;
600613 private String applicationId ;
601614 private String clientKey ;
@@ -604,6 +617,8 @@ public static final class Builder {
604617 private boolean allowCustomObjectId ;
605618 private OkHttpClient .Builder clientBuilder ;
606619 private int maxRetries = DEFAULT_MAX_RETRIES ;
620+ private int maxKeyValueCacheBytes = DEFAULT_MAX_KEY_VALUE_CACHE_BYTES ;
621+ private int maxKeyValueCacheFiles = DEFAULT_MAX_KEY_VALUE_CACHE_FILES ;
607622
608623 /**
609624 * Initialize a bulider with a given context.
@@ -707,6 +722,36 @@ public Builder maxRetries(int maxRetries) {
707722 return this ;
708723 }
709724
725+ /**
726+ * Set the maximum amount of bytes to use for the Parse cache on disk. Defaults to
727+ * {@link Builder#DEFAULT_MAX_KEY_VALUE_CACHE_BYTES}.
728+ *
729+ * @param maxKeyValueCacheBytes The maximum number of bytes to use for the cache.
730+ * @return The same builder, for easy chaining.
731+ */
732+ public Builder maxKeyValueCacheBytes (int maxKeyValueCacheBytes ) {
733+ if (maxKeyValueCacheBytes < 0 ) {
734+ throw new IllegalArgumentException ("maxKeyValueCacheBytes must be >= 0" );
735+ }
736+ this .maxKeyValueCacheBytes = maxKeyValueCacheBytes ;
737+ return this ;
738+ }
739+
740+ /**
741+ * Set the maximum number of files to store in the Parse cache on disk. Defaults to
742+ * {@link Builder#DEFAULT_MAX_KEY_VALUE_CACHE_FILES}.
743+ *
744+ * @param maxKeyValueCacheFiles The maximum number of files to store in the cache.
745+ * @return The same builder, for easy chaining.
746+ */
747+ public Builder maxKeyValueCacheFiles (int maxKeyValueCacheFiles ) {
748+ if (maxKeyValueCacheFiles < 0 ) {
749+ throw new IllegalArgumentException ("maxKeyValueCacheFiles must be >= 0" );
750+ }
751+ this .maxKeyValueCacheFiles = maxKeyValueCacheFiles ;
752+ return this ;
753+ }
754+
710755 /**
711756 * Construct this builder into a concrete {@code Configuration} instance.
712757 *
0 commit comments