AWS Amplify API
AWS Amplify Home
Options
All

- Public
- Public/Protected
- All

Inherited Externals Only exported
Menu

Customized storage based on the SessionStorage or LocalStorage with LRU implemented

### Hierarchy

- StorageCache
  - BrowserStorageCache

### Implements

- any

## Index

### Constructors

- constructor

### Properties

- cacheCurSizeKey
- config

### Methods

- clear
- configure
- createInstance
- fillCacheItem
- getAllKeys
- getCacheCurSize
- getItem
- getModuleName
- removeItem
- setItem

## Constructors

### constructor

- new BrowserStorageCache(config?: CacheConfig): BrowserStorageCache

- Overrides StorageCache.constructor

  - Defined in cache/src/BrowserStorageCache.ts:28

  initialize the cache

  #### Parameters

  - ##### Optional config: CacheConfig

    the configuration of the cache

  #### Returns BrowserStorageCache

## 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

### clear

- clear(): void

- - Defined in cache/src/BrowserStorageCache.ts:393

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

  #### Returns 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: CacheConfig): ICache

- - Defined in cache/src/BrowserStorageCache.ts:449

  Return a new instance of cache with customized configuration.

  #### Parameters

  - ##### config: CacheConfig

    the customized configuration

  #### Returns ICache

  - 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(): string[]

- - Defined in cache/src/BrowserStorageCache.ts:418

  Return all the keys in the cache.

  #### Returns string[]

  - all keys in the cache

### getCacheCurSize

- getCacheCurSize(): number

- - Defined in cache/src/BrowserStorageCache.ts:434

  return the current size of the cache

  #### Returns number

  - current size of the cache

### getItem

- getItem(key: string, options?: CacheItemOptions): any

- - Defined in cache/src/BrowserStorageCache.ts:325

  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 browser storage

  #### Parameters

  - ##### key: string

    the key of the item

  - ##### Optional options: CacheItemOptions

  #### Returns any

  - return the value of the item

### getModuleName

- getModuleName(): string

- Inherited from StorageCache.getModuleName

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

  #### Returns string

### removeItem

- removeItem(key: string): void

- - Defined in cache/src/BrowserStorageCache.ts:370

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

  #### Parameters

  - ##### key: string

    the key of the item

  #### Returns void

### setItem

- setItem(key: string, value: any | number | string | boolean, options?: CacheItemOptions): void

- - Defined in cache/src/BrowserStorageCache.ts:248

  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: string

    the key of the item

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

    the value of the item

  - ##### Optional options: CacheItemOptions

  #### Returns void