new AsyncStorageCache(config)
initialize the cache
Parameters:
Name | Type | Description |
---|---|---|
config |
Object | the configuration of the cache |
- Source:
Methods
(async) clear() → {Promise}
clear the entire cache
The cache will abort output a warning:
If error happened with AsyncStorage
- Source:
Returns:
- Type
- Promise
createInstance(config) → {Object}
Return a new instance of cache with customized configuration.
Parameters:
Name | Type | Description |
---|---|---|
config |
Object | the customized configuration |
- Source:
Returns:
- the new instance of Cache
- Type
- Object
(async) getAllKeys() → {Promise}
Return all the keys in the cache.
Will return an empty array if error happend.
- Source:
Returns:
- Type
- Promise
(async) getCacheCurSize() → {Promise}
return the current size of the cache
- Source:
Returns:
- Type
- Promise
(async) getItem(key, optionsopt) → {Promise}
Get item from cache. It will return null if item doesn’t exist or it has been expired.
If you specified callback function in the options,
then the function will be executed if no such item in the cache
and finally put the return value into cache.
Please make sure the callback function will return the value you want to put into the cache.
The cache will abort output a warning:
If the key is invalid
If error happened with AsyncStorage
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
key |
String | the key of the item | |
options |
Object |
<optional> |
the options of callback function |
- Source:
Returns:
- return a promise resolves to be the value of the item
- Type
- Promise
(async) removeItem(key) → {Promise}
remove item from the cache
The cache will abort output a warning:
If error happened with AsyncStorage
Parameters:
Name | Type | Description |
---|---|---|
key |
String | the key of the item |
- Source:
Returns:
- Type
- Promise
(async) setItem(key, value, optionsopt) → {Prmoise}
Set item into cache. You can put number, string, boolean or object.
The cache will first check whether has the same key.
If it has, it will delete the old item and then put the new item in
The cache will pop out items if it is full
You can specify the cache item options. The cache will abort and output a warning:
If the key is invalid
If the size of the item exceeds itemMaxSize.
If the value is undefined
If incorrect cache item configuration
If error happened with browser storage
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
key |
String | the key of the item | |
value |
Object | the value of the item | |
options |
Object |
<optional> |
optional, the specified meta-data |
- Source:
Returns:
- Type
- Prmoise