A Prisma middleware for caching database queries in Redis with in-memory fallback and cache invalidation.
prisma-redis-middleware is a caching middleware for Prisma ORM that stores database query results in Redis, with an in-memory LRU cache as a fallback. It reduces database load and speeds up applications by caching frequently accessed data, with support for cache invalidation and per-model configuration.
Backend developers using Prisma ORM in Node.js applications who need to optimize database performance through query caching.
It provides a flexible, Prisma-native caching solution with Redis persistence, granular control over cached models and methods, and built-in cache invalidation, avoiding manual cache management.
Prisma Middleware for caching queries in Redis
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Allows per-model configuration of cache times and exclusion of specific methods, as demonstrated in the 'models' array option with cacheTime and excludeMethods.
Automatically invalidates cached data when related models are updated using the 'invalidateRelated' option, ensuring data consistency without manual intervention.
Stores cache in Redis for durability and uses an in-memory LRU cache as fallback, as shown in the storage options, providing resilience if Redis is unavailable.
Includes onHit, onMiss, onError, and onDedupe callbacks for monitoring cache performance, enabling easy troubleshooting and optimization.
The README explicitly states that 'queryRaw' methods are not cached, limiting its usefulness for applications relying heavily on raw SQL queries.
Requires separate setup and management of Redis and a client like ioredis, adding infrastructure complexity and potential points of failure.
Options such as 'invalidation.referencesTTL' need precise tuning to avoid cache staleness or performance issues, which can be error-prone for inexperienced users.