Skip to Content
FrontendBundlesCacheCache

Cache

Introduction

A cache library designed to simplify reusability of dynamodb functions in projects, providing commonly used cache functions.


Installation

To use @phpcreation/frontend-dynamodb-react-nextjs-bundle in your project, follow these steps:

Open a terminal in your project root

Create a Github Personnal Access Token

Create a Github Personal Access Token

Login to NPM registry

npm login --scope=@phpcreation --auth-type=legacy --registry=https://npm.pkg.github.com
  • username: your github username in lowercase
  • password: The PAT you just created

Install the Package

npm install @phpcreation/frontend-dynamodb-react-nextjs-bundle

Setup

Environment Variables

Follow these steps to manage environment variables correctly :

Environment Variables Management

.env.local

These variables should be sent to the secrets of the deployed app. and not committed to version control.

# Caching dynamodb # Table and runtime DYNAMODB_APP_CACHE_TABLE= # The name of the dynamodb table you want to use for caching DYNAMODB_RUNTIME= # The runtime of the dynamodb table either "aws" or "local" # Region CUSTOM_AWS_REGION= # The aws region of the dynamodb table # Credentials CUSTOM_AWS_ACCESS_KEY_ID= # Your AWS access key id CUSTOM_AWS_SECRET_ACCESS_KEY= # Your AWS secret access key

Usage

Make sure to follow naming conventions for cache keys. For more information, see our Caching Naming Convention.

Caching Naming Convention

Example

import { storeToCache, getCachedData, } from "@phpcreation/frontend-dynamodb-react-nextjs-bundle/dynamodb"; const data = { id: 1, name: "John Doe", age: 30, email: "johndoe@email.com", }; // Ensure the prefix follows the caching keys naming convention : // tenant_corporation-id_user-id_section // (https://dev.react-doc.phpr.link/structure/naming-conventions/caching-keys) const prefix = "demo_5_83_user-"; await storeToCache(`${prefix}${data.id}`, data); const cachedData = await getCachedData(`${prefix}${data.id}`);

Common Issues

Common Issues
Last updated on