TRPC + Prisma Caching
Hey. I'm using trpc middlewares to inject the authenticated user (from the db using prisma) to the procedure's context. each request makes at least one DB query and thats expensive. i already have a redis database for other reasons and I'd like to introduce caching of users. the point is that the application is heavily dependent on the user so it is not acceptable to get outdated.
my idea was to use redis with the key of the userid and the value is the the user data. when there is an entry in the cache, we use that instead of the using the db. on any kind of user update, we remove the that users entry from the redis db.
what do you think about this approach/strategy?
3 Replies
queries like that aren't expensive
but if you are really interested in using redis
@next-auth/upstash-redis-adapter | Auth.js
Official Upstash Redis adapter for Auth.js / NextAuth.js.
unfortunately i'm using clerk
but will looking that the code