I have a api key check that will use pg table lookup.
I want to know if there’s a way to cache this api key check (if api key is valid) and jump straight to logic (i.e. if the key has enough quota).
I’ve looked at golang production scaling tutorials but I couldn’t find anything similar to this.
Would it be a good solution for scaling, or a over engineering, and I should just let the db handle the query?
Hey @testingcodehere, great question. Encore has built-in support for Redis caching which is easy to use. That said, for your use case it’s probably going to be only marginally faster than the database query since the bottleneck is going to be the cost of the network request in both cases (since you’re not computing anything expensive, just doing an index lookup).
If I were you I would probably use an in-memory cache for this use case. I would recommend github.com/hashicorp/golang-lru/v2 for this, which is an easy-to-use cache with support for generics. You can easily use it in your Encore service with a service struct.