Cache custom fields

Hi I'm using Next auth with jwt and a whole bunch of custom session fields that are used for authorization. I really would like to migrate to Better Auth but using db for every call (eg all my trpc routes) seems like a massive performance hit. I read you can use cached sessions and also add custom fields to sessions, so this would fix everything. Unfortunately the docs also say that custom fields can't be cached. Is there a solution?
2 Replies
LightTab2
LightTab22w ago
I have inspected the code and the "basic" session fields are cached, so when you customSession is called, the session argument comes from cache if valid. This means you can cache your custom fields inside customSession on your own and you're good to go. I am 80% sure I inspected the code right.
Kaeon
KaeonOP2w ago
Thanks! Then I will definitely check that, confusing docs then though

Did you find this page helpful?