diff --git a/README.md b/README.md index 006834c9..2e4ac152 100644 --- a/README.md +++ b/README.md @@ -58,8 +58,8 @@ getData = async () => { } ``` - -See docs for [api and more examples](docs/API.md), and [brownfield integration guide](docs/AdvancedUsage.md). +### Advanced +See docs for [api and more examples](docs/API.md) or [advanced usages](docs/advanced). ## Writing tests diff --git a/android/build.gradle b/android/build.gradle index 1d0cb61c..a0f27701 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -18,6 +18,18 @@ def getExtOrIntegerDefault(name) { return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['RNAsyncStorage_' + name]).toInteger() } +// AsyncStorage has default size of 6MB. +// This is a sane limit to protect the user from the app storing too much data in the database. +// This also protects the database from filling up the disk cache and becoming malformed. +// If you really need bigger size, please keep in mind the potential consequences. +long dbSizeInMB = 6L + +def newDbSize = rootProject.properties['AsyncStorage_db_size_in_MB'] + +if( newDbSize != null && newDbSize.isLong()) { + dbSizeInMB = newDbSize.toLong() +} + apply plugin: 'com.android.library' android { @@ -27,6 +39,8 @@ android { defaultConfig { minSdkVersion getExtOrIntegerDefault('minSdkVersion') targetSdkVersion getExtOrIntegerDefault('targetSdkVersion') + + buildConfigField "Long", "AsyncStorage_db_size", "${dbSizeInMB}L" } } @@ -37,4 +51,3 @@ repositories { dependencies { implementation 'com.facebook.react:react-native:+' } - \ No newline at end of file diff --git a/android/src/main/java/com/reactnativecommunity/asyncstorage/ReactDatabaseSupplier.java b/android/src/main/java/com/reactnativecommunity/asyncstorage/ReactDatabaseSupplier.java index 9f992ca4..6e191de2 100644 --- a/android/src/main/java/com/reactnativecommunity/asyncstorage/ReactDatabaseSupplier.java +++ b/android/src/main/java/com/reactnativecommunity/asyncstorage/ReactDatabaseSupplier.java @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ - + package com.reactnativecommunity.asyncstorage; import javax.annotation.Nullable; @@ -43,7 +43,7 @@ public class ReactDatabaseSupplier extends SQLiteOpenHelper { private Context mContext; private @Nullable SQLiteDatabase mDb; - private long mMaximumDatabaseSize = 6L * 1024L * 1024L; // 6 MB in bytes + private long mMaximumDatabaseSize = BuildConfig.AsyncStorage_db_size * 1024L * 1024L; private ReactDatabaseSupplier(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); diff --git a/docs/AdvancedUsage.md b/docs/advanced/BrownfieldIntegration.md similarity index 100% rename from docs/AdvancedUsage.md rename to docs/advanced/BrownfieldIntegration.md diff --git a/docs/advanced/IncreaseDbSize.md b/docs/advanced/IncreaseDbSize.md new file mode 100644 index 00000000..b2c36bde --- /dev/null +++ b/docs/advanced/IncreaseDbSize.md @@ -0,0 +1,20 @@ +# Increase Async Storage size + +## Android + +Current Async Storage's size is set to 6MB. Going over this limit causes `database or disk is full` error. This 6MB limit is a sane limit to protect the user from the app storing too much data in the database. This also protects the database from filling up the disk cache and becoming malformed (endTransaction() calls will throw an exception, not rollback, and leave the db malformed). You have to be aware of that risk when increasing the database size. We recommend to ensure that your app does not write more data to AsyncStorage than space is left on disk. Since AsyncStorage is based on SQLite on Android you also have to be aware of the [SQLite limits](https://www.sqlite.org/limits.html). + +### Increase limit + +Add a `AsyncStorage_db_size_in_MB` property to your `android/gradle.properties`: + +``` +AsyncStorage_db_size_in_MB=10 +``` + +Now you can define the new size in MB. In this example, the new limit is 10 MB. + + +## iOS + +Async Storage size is not limited programmatically on iOS. diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 89e0d99e..c841003e 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -16,3 +16,6 @@ # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true + +# This is an example of how you can change default DB size (6MB) to 10MB +# AsyncStorage_db_size_in_MB=10