React-native: AsyncStorage Size in the Docs

Created on 13 Oct 2015  路  20Comments  路  Source: facebook/react-native

Just a quick change that would be great to see in the docs, is to list the size of AsyncStorage. This was answered by @ide in a StackOverflow question: http://stackoverflow.com/questions/32875726/how-large-is-asyncstorage-in-react-native

AsyncStorage Locked

Most helpful comment

@andreicoman11 can you please give some advice as to where should I call setMaximumSize in a project?

All 20 comments

@ryanmcdermott - PR welcome!

@brentvatne Would love to! Do you know if AsyncStorage lacks a storage cap in Android as well?

@ryanmcdermott - not sure actually, cc @kmagiera

I believe @andreicoman11 has been changing this recently

On android we set a limit of 6mb.

Any reason not to set it to something like 100-500MB? Micro SD cards these days are easily 16-64GB.

+1 for a bigger default than 6MB

I think android and iOS deal with this differently. On android, cache information should not be stored in databases, but in files in designated cache folders which can then be cleaned up when necessary. Databases should be used to store information that is absolutely necessary for the app, information that cannot be automatically reclaimed by the system.
With that in mind, a database should not need to grow bigger then the limit set right now.
However, since there's no way to use any other caching mechanism from within react native, an intermediate solution would be to make it possible to database size limit configurable.
PS: android devices are much more prone to memory issues than iOS devices. Even with the possibility of extra micro SD cards, many android devices will regularly run into problems with not having enough memory for caching purposes. Apps should be designed in such a way to properly deal with this.
PPS: careful with storing any sort of information on SD cards! Any user data stored on the SD card has to be properly encrypted (our database for example is not encrypted). Otherwise, you can run into privacy violation issues.

I think this is still relevant.
If you give us only 6MB, then i'd somehow like to know how much free space I still have. Nowhere in the API can i find something like that. What will happen when i hit the limit? Will it just throw an error?

Could we have bigger size of async storage? Or at least make it configurable? 6mb is kind of nothing for modern phones.

You can set the maximum size of the database via setMaximumSize.
As mentioned before, careful with doing this. If you need more than 6MB to be stored in the database (not in cache, which is a different issue), then you are most likely doing something wrong.

@andreicoman11 can you please give some advice as to where should I call setMaximumSize in a project?

@andreicoman11 Why shouldn't apps store more than 6MB in their local databases? Seems true under the assumption of relatively light clients. P2P applications, however, might well expect to save more than 6MB worth of data (as one example)

BTW @kapv89, I haven't tried this out, but looks like you can call ReactDatabaseSupplier.getInstance(getApplicationContext()).setMaximumSize(/*x bytes*/) in your main Activity

Ref: https://github.com/facebook/react-native/blob/0.33-stable/ReactAndroid/src/main/java/com/facebook/react/modules/storage/ReactDatabaseSupplier.java#L55

Hi! I changed the setMaximumSize but still having problems. I get this error: Couldn't read row 0, col 0 from CursorWindow

@agrass Were you ever able to solve the issue? I have the same error.

@andreicoman11 @brentvatne Why is wrong to use more than 6mb with AsyncStorage? You mean more than 6mb in one key/value element right? The whole key/values of AsyncStorage together could be greater than that size?

Anyone with another solution? because store the data on the disk is a little slow if you need to persist frequently.

@agrass Did you find out something about the limit? Is it for each key or for all?

Hi set ReactDatabaseSupplier.getInstance(getApplicationContext()).setMaximumSize(600L * 1024L * 1024L);
In MainApplication.java I successfully ride of max size warning but when I get data I got same warning as @agrass and can't get tha data back( I am storing image uri in storage)

can anyone help me ?

@carlosscheffer @KishanIos007 I think that the best solution right now is just to change the code to store less data in one key of AsyncStorage, and instead of that store in different keys/values of AsyncStorage or in the disk.

Was this page helpful?
0 / 5 - 0 ratings