Skip to main content

Elevate Web Cache Model

Description

Elevate Web includes/has plans to integrate several cache layers:

  • Route cache: Elevate Web should (not yet implemented) a per route (instance) cache to ensure that a user will get a fast route response whenever possible
  • Service/Provider cache: Elevate Web should (not yet implemented) a per Service/Provider method response cache (after parsing).
  • Fetch/Request cache: Elevate Web implements a per http/request cache
  • Memory cache to store Accedo Control session to keep avoid repeated /session request

Route cache Details

To Be defined.

We need to investigate how to use Next.js capabilities to optimize how routes are cached

Service/Provider cache Details

The initial Service/Provider cache configuration model was defined to be mixed within the Fetch/Request cache but we finally remove it from the Fetch cache opting for a more simplistic implementation, but the initial setup/config process is done in:

  • src/services/config.ts
  • src/services/manager.ts
  • src/services/cache.ts

and the initial config usage and extra service fetcher utility was created in:

  • src/utils/fetcher.ts

The implementation on the Providers is planned to be done using Typescript Decorator as done in E&L PS Global Middleware and a cache system with serviceName-methodName key model but it's not implemented.

Fetch/Request cache

Using the Next.js request cache and a default revalidate for all the Next.js routes from the default layout

warning

Next.js doesn't allow to define the revalidate value on config and the appInitialization is done before routes/layout are handled from Next.js

In-Memory cache

We have created the file src/utils/memoryCache.ts to implement a very basic memory store cache.

There we define the possible keys for such store (initally just CONTROL_SESSION_KEY) but more can be added if it fits the projects needs.

Methods

  • get: get a cache if exists from the memory cache. Params: key
  • set: set a cache value based on the provided key and value;. Params key, value

Exports

  • CacheKeysTypes: enum of keys for the Memory Cache.
  • CacheKeysTypesKeys: Union of the keys for the Memory cache.
  • MemoryCacheType: Memory Cache type for casting.
  • MemoryCacheType: Memory cache class

Usage

import { MemoryCache } from '@/utils/memoryCache';

const cache = MemoryCache.getInstance();
const prevValue = cache.get('key');
cache.set('key', newValuer);