Skip to main content

How do I store data in the cache?

Objective: This article explains how to use the cache to store and retreive data.

Steps:

  1. Append a new cacheKey in components/cache/index.ts.
  2. 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: