AWS Amplify API
AWS Amplify Home
Options
All

- Public
- Public/Protected
- All

Inherited Externals Only exported
Menu

### Hierarchy

- StorageCache
  - AsyncStorageCache

### Implements

- any

## Index

### Constructors

- constructor

### Properties

- cacheCurSizeKey
- config

### Methods

- _decreaseCurSizeInBytes
- _findValidKeys
- _increaseCurSizeInBytes
- _isCacheFull
- _isExpired
- _popOutItems
- _refreshItem
- _removeItem
- _setItem
- _sizeToPop
- clear
- configure
- createInstance
- fillCacheItem
- getAllKeys
- getCacheCurSize
- getItem
- getModuleName
- removeItem
- setItem

## Constructors

### constructor

- new AsyncStorageCache(config?: any): AsyncStorageCache

- Overrides StorageCache.constructor

  - Defined in cache/src/AsyncStorageCache.ts:25

  initialize the cache

  #### Parameters

  - ##### Optional config: any

    the configuration of the cache

  #### Returns AsyncStorageCache

## Properties

### Protected cacheCurSizeKey

cacheCurSizeKey: string

Inherited from StorageCache.cacheCurSizeKey

- Defined in cache/src/StorageCache.ts:31

### Protected config

config: CacheConfig

Inherited from StorageCache.config

- Defined in cache/src/StorageCache.ts:32

## Methods

### Private _decreaseCurSizeInBytes

- _decreaseCurSizeInBytes(amount: any): Promise<void>

- - Defined in cache/src/AsyncStorageCache.ts:46

  decrease current size of the cache

  #### Parameters

  - ##### amount: any

    the amount of the cache size which needs to be decreased

  #### Returns Promise<void>

### Private _findValidKeys

- _findValidKeys(): Promise<any[]>

- - Defined in cache/src/AsyncStorageCache.ts:164

  scan the storage and find out all the keys owned by this cache also clean the expired keys while scanning

  #### Returns Promise<any[]>

  array of keys

### Private _increaseCurSizeInBytes

- _increaseCurSizeInBytes(amount: any): Promise<void>

- - Defined in cache/src/AsyncStorageCache.ts:56

  increase current size of the cache

  #### Parameters

  - ##### amount: any

    the amount of the cache szie which need to be increased

  #### Returns Promise<void>

### Private _isCacheFull

- _isCacheFull(itemSize: any): Promise<boolean>

- - Defined in cache/src/AsyncStorageCache.ts:154

  see whether cache is full

  #### Parameters

  - ##### itemSize: any

  #### Returns Promise<boolean>

  true if cache is full

### Private _isExpired

- _isExpired(key: any): Promise<boolean>

- - Defined in cache/src/AsyncStorageCache.ts:83

  check wether item is expired

  #### Parameters

  - ##### key: any

    the key of the item

  #### Returns Promise<boolean>

  true if the item is expired.

### Private _popOutItems

- _popOutItems(keys: any, sizeToPop: any): Promise<void>

- - Defined in cache/src/AsyncStorageCache.ts:191

  get all the items we have, sort them by their priority, if priority is same, sort them by their last visited time pop out items from the low priority (5 is the lowest)

  #### Parameters

  - ##### keys: any

    all the keys in this cache

  - ##### sizeToPop: any

    the total size of the items which needed to be poped out

  #### Returns Promise<void>

### Private _refreshItem

- _refreshItem(item: any, prefixedKey: any): Promise<any>

- - Defined in cache/src/AsyncStorageCache.ts:69

  update the visited time if item has been visited

  #### Parameters

  - ##### item: any

    the item which need to be refreshed

  - ##### prefixedKey: any

    the key of the item

  #### Returns Promise<any>

  the refreshed item

### Private _removeItem

- _removeItem(prefixedKey: any, size?: any): Promise<void>

- - Defined in cache/src/AsyncStorageCache.ts:98

  delete item from cache

  #### Parameters

  - ##### prefixedKey: any

    the key of the item

  - ##### Optional size: any

    optional, the byte size of the item

  #### Returns Promise<void>

### Private _setItem

- _setItem(prefixedKey: any, item: any): Promise<void>

- - Defined in cache/src/AsyncStorageCache.ts:120

  put item into cache

  #### Parameters

  - ##### prefixedKey: any

    the key of the item

  - ##### item: any

  #### Returns Promise<void>

### Private _sizeToPop

- _sizeToPop(itemSize: any): Promise<number>

- - Defined in cache/src/AsyncStorageCache.ts:141

  total space needed when poping out items

  #### Parameters

  - ##### itemSize: any

  #### Returns Promise<number>

  total space needed

### clear

- clear(): Promise<void>

- - Defined in cache/src/AsyncStorageCache.ts:383

  clear the entire cache The cache will abort output a warning: If error happened with AsyncStorage

  #### Returns Promise<void>

### configure

- configure(config?: CacheConfig): CacheConfig

- Inherited from StorageCache.configure

  - Defined in cache/src/StorageCache.ts:128

  set cache with customized configuration

  #### Parameters

  - ##### Optional config: CacheConfig

    customized configuration

  #### Returns CacheConfig

  - the current configuration

### createInstance

- createInstance(config: any): ICache

- - Defined in cache/src/AsyncStorageCache.ts:445

  Return a new instance of cache with customized configuration.

  #### Parameters

  - ##### config: any

    the customized configuration

  #### Returns ICache

  - the new instance of Cache

### Protected fillCacheItem

- fillCacheItem(key: string, value: any | number | string | boolean, options: CacheItemOptions): CacheItem

- Inherited from StorageCache.fillCacheItem

  - Defined in cache/src/StorageCache.ts:101

  produce a JSON object with meta-data and data value

  #### Parameters

  - ##### key: string

  - ##### value: any | number | string | boolean

    the value of the item

  - ##### options: CacheItemOptions

    optional, the specified meta-data

  #### Returns CacheItem

  - the item which has the meta-data and the value

### getAllKeys

- getAllKeys(): Promise<any[]>

- - Defined in cache/src/AsyncStorageCache.ts:423

  Return all the keys in the cache. Will return an empty array if error happend.

  #### Returns Promise<any[]>

### getCacheCurSize

- getCacheCurSize(): Promise<number>

- - Defined in cache/src/AsyncStorageCache.ts:408

  return the current size of the cache

  #### Returns Promise<number>

### getItem

- getItem(key: any, options: any): Promise<any>

- - Defined in cache/src/AsyncStorageCache.ts:314

  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

  - ##### key: any

    the key of the item

  - ##### options: any

  #### Returns Promise<any>

  - return a promise resolves to be the value of the item

### getModuleName

- getModuleName(): string

- Inherited from StorageCache.getModuleName

  - Defined in cache/src/StorageCache.ts:44

  #### Returns string

### removeItem

- removeItem(key: any): Promise<void>

- - Defined in cache/src/AsyncStorageCache.ts:359

  remove item from the cache The cache will abort output a warning: If error happened with AsyncStorage

  #### Parameters

  - ##### key: any

    the key of the item

  #### Returns Promise<void>

### setItem

- setItem(key: any, value: any, options: any): Promise<void>

- - Defined in cache/src/AsyncStorageCache.ts:244

  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

  - ##### key: any

    the key of the item

  - ##### value: any

    the value of the item

  - ##### options: any

  #### Returns Promise<void>