Skip to main content

Cache

Overview

The purpose of this component is to provide a cache implementation for a number of selected cache providers. Currently the cache component supports the following engines:

  • In Memory - Utilizes node-cache to provide an in-memory cache.
  • Redis - Utilizes ioredis to provide a redis cache.

Usage

  1. Set the cache variables in the configuration.ts file to choose the engine you wish to use.
  2. Import the cache implementation using the following code:
import { cache } from '@hectare/platform.components.cache'

...

await cache.set(...)
await cache.get(...)

Note: The imported cache is a singleton and will load the desired cache implementation at runtime.

See the ICache interface for a list of public functions that can be used.

Redis - Local Testing

If you wish to use the Redis cache implementation, you must be running an instance of Redis on your local environment. The easiest way to achieve this is by using the Docker Redis Image.

docker pull redis
docker run -p 6379:6379 redis