Skip to Content
FrontendAppsInventoryClear Cache Script Documentation

Clear Cache Script Documentation

Introduction

The clear-cache script is a tool that allows you to clear all cache entries for both the application and configuration.

The script is located at scripts/clear-cache.ts and can be run locally or through npm scripts.

Prerequisites

Before running the script, ensure you have:

  1. Environment Variables: The following environment variables must be set:

    • DYNAMODB_DSN_APP_CACHE - DynamoDB connection string for the app cache table
    • DYNAMODB_DSN_CONFIG - DynamoDB connection string for the config cache table
  2. Dependencies Installed: Run pnpm install to ensure all dependencies, including tsx, are installed.

Usage

Using npm script

The easiest way to run the script is using the npm script:

# Load environment variables and run the script pnpm clear-cache

This command will:

  1. Run loadEnv.sh to load the appropriate environment file based on APP_ENV
  2. Execute the clear-cache script using tsx

Using a specific environment

You can specify the environment by setting the APP_ENV variable:

# For dev environment APP_ENV=dev pnpm clear-cache # For staging environment APP_ENV=staging pnpm clear-cache # For production environment APP_ENV=prod pnpm clear-cache

Running directly with tsx

You can also run the script directly using tsx:

pnpm tsx scripts/clear-cache.ts

Make sure to set APP_ENV and load environment variables first if needed.

How It Works

The script performs the following steps:

  1. Loads Environment Variables:

    • First attempts to load from .env.local (created by loadEnv.sh)
    • If APP_ENV is set, also loads from ./environments/.env.${APP_ENV}
  2. Connects to DynamoDB:

    • Uses getCache() to connect to the app cache table
    • Uses getConfigCache() to connect to the config cache table
  3. Clears Caches:

    • Calls deleteAll() on both cache instances to remove all entries
    • Provides console feedback for each step
  4. Exits:

    • Exits with code 0 on success
    • Exits with code 1 on error
Last updated on