Skip to content

Variable: forceUpdateCache$

const forceUpdateCache$: Subject<string | boolean | string[]>

Defined in: store/src/Store.ts:74

RxJS Subject to trigger forced update of cached data from underlying storage of Store instances.

Accepted values:

  • string: Updates the cache for the instance with the matching name.
  • string[]: Updates the cache for all instances whose names are included in the array.
  • true: Triggers a global cache update for all instances that have a name defined.
  • false: No-op.

Examples

javascript
import { Store, forceUpdateCache$ } from '@superutils/store'

const names = ['products', 'users']

// Update all Store instances by a list of their names
forceUpdateCache$.next(names)
// alternatively: Store.forceUpdateCache(names)

// Update all Store instances with a specific name
forceUpdateCache$.next(names[0])
// alternatively: Store.forceUpdateCache(names[0])

// Update every single instance of Store that uses storage (has a "name" property)
forceUpdateCache$(true)
// alternatively: Store.forceUpdateCache(true)

Practical example

typescript
import { createStore, forceUpdateCache$ } from '@superutils/store'

const name = 'user-profile'
const delay = 0 // delay is set to zero to simplify the example

const userStore = createStore(name, { delay })
const userStore2 = createStore(name, { delay })

userStore.init()
userStore2.init()

userStore.set('name', 'John Doe')
console.log(userStore2.get('name')) // Prints: undefined

forceUpdateCache$.next(name)
console.log(userStore2.get('name')) // Prints: 'John Doe'