https://github.com/prisma/prisma-accelerate-invalidation
https://github.com/prisma/prisma-accelerate-invalidation
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/prisma/prisma-accelerate-invalidation
- Owner: prisma
- License: apache-2.0
- Created: 2024-11-01T14:08:22.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-22T16:20:21.000Z (over 1 year ago)
- Last Synced: 2025-04-11T16:11:20.074Z (about 1 year ago)
- Language: TypeScript
- Homepage: https://test-cache-invalidation.prisma.io
- Size: 46.3 MB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Prisma Accelerate Cache Invalidation Test
This project demonstrates [cache invalidation](https://www.prisma.io/docs/accelerate/caching#on-demand-cache-invalidation) timing in a Next.js application using Prisma and [Prisma Accelerate](https://www.prisma.io/accelerate), with a Time-to-Live (TTL) strategy. It measures the time it takes for cache invalidation to reflect updated data.
## Application overview
The app provides an interactive interface to test cache invalidation behavior.

### How it works:
1. A quote is fetched with a TTL of 60 seconds.
2. The fetched quote is cached.
3. The quote is updated in the database.
4. The cache is invalidated using Prisma Accelerate's `$invalidate` API.
5. The app polls the API until the updated quote is fetched.
6. The total time for invalidation to take effect is displayed, including frontend-to-backend roundtrip delays.
## Prerequisites
Before you begin, ensure you have the following prerequisites:
- Obtain an Accelerate API key from [Prisma Data Platform](https://pris.ly/pdp).
- Create a `.env` file in the project root directory with the following content:
```bash
# Accelerate connection string
DATABASE_URL="prisma://accelerate.prisma-data.net/?api_key=ACCELERATE_API_KEY"
# To run migrations
DIRECT_URL="postgresql://username:password@host:5432/database_name"
```
## Getting Started
To get started with this project, follow these steps:
1. Install project dependencies:
```bash
npm install
```
2. Set up Prisma by running migrations and generating a PrismaClient for edge functions:
```bash
npx prisma migrate dev
npx prisma db seed
npx prisma generate --no-engine
```
3. Start the application:
```bash
npm run dev
```
The app will run at http://localhost:3000.
## How to use the app
1. Click the “Start cache invalidation test” button on the homepage.
2. Observe the timeline for cache invalidation and updated data retrieval.
3. Review the displayed total invalidation time.
## Contributing
Contributions are welcome! Feel free to open issues or submit pull requests to improve this project.