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:
-
Environment Variables: The following environment variables must be set:
DYNAMODB_DSN_APP_CACHE- DynamoDB connection string for the app cache tableDYNAMODB_DSN_CONFIG- DynamoDB connection string for the config cache table
-
Dependencies Installed: Run
pnpm installto ensure all dependencies, includingtsx, 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-cacheThis command will:
- Run
loadEnv.shto load the appropriate environment file based onAPP_ENV - 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-cacheRunning directly with tsx
You can also run the script directly using tsx:
pnpm tsx scripts/clear-cache.tsMake sure to set APP_ENV and load environment variables first if needed.
How It Works
The script performs the following steps:
-
Loads Environment Variables:
- First attempts to load from
.env.local(created byloadEnv.sh) - If
APP_ENVis set, also loads from./environments/.env.${APP_ENV}
- First attempts to load from
-
Connects to DynamoDB:
- Uses
getCache()to connect to the app cache table - Uses
getConfigCache()to connect to the config cache table
- Uses
-
Clears Caches:
- Calls
deleteAll()on both cache instances to remove all entries - Provides console feedback for each step
- Calls
-
Exits:
- Exits with code 0 on success
- Exits with code 1 on error