How do I store data in the cache?
Objective: This article explains how to use the cache to store and retreive data.
Steps:
- Append a new
cacheKey
incomponents/cache/index.ts
. - Use the
cache
object to store and retrieve data.
Example:
import { cache, cacheKeys } from '@hectare/platform.components.cache'
import { configuration } from '@hectare/platform.components.configuration'
const value = await cache.get(
cacheKeys.yourCacheKey,
async (): Promise<any> => {
// This function is used to fetch the data you want to cache.
return 'Some cached value'
},
configuration.cache.timeouts.fifteenMinutes // How long it will be cached
)
Related Articles: