darkweak / souin

An HTTP cache system, RFC compliant, compatible with @tyktechnologies, @traefik, @caddyserver, @go-chi, @bnkamalesh, @beego, @devfeel, @labstack, @gofiber, @go-goyave, @go-kratos, @gin-gonic, @roadrunner-server, @zalando, @zeromicro, @nginx and @apache

Home Page:https://docs.souin.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fallback to a different cache system (local => distributed)

dkarlovi opened this issue · comments

Let's say we want to use Redis or a similar distributed system as a backend.

We could have a chain of cache providers like using say Badger+Redis, this way Badger could keep the local copy in memory for hot items, but check Redis on a miss. This would allow to optimize network traffic and memory usage across multiple Souin nodes.

Say we have two Caddy+Souin nodes, S1 and S2, each with say 2GB of dedicated RAM locally. We also have a Redis cluster with say 32GB.

How it would work is both S1 and S2 would have local copies of hot items which they can serve very quickly, but on a miss they'd query Redis before passing the request. It would minimize both duplication, memory and network use and involved latency (since the nodes would be self-sufficient in many cases, assuming 80/20 rule) but would still take advantage of a big memory pool and not pass too often because their own cache pool is small. It would work almost as if both nodes have 34GB of RAM each.

The only drawback would be invalidation where you'd need to invalidate all instances in the Souin pool when you purge, but that's already an issue if you're using two local Souin instances AFAIK?

Sidenote: is Redis supported as a backend with Caddy? I see it should be supported with Traefik, but there's nothing in the docs. Nevermind, it's in the cache plugin docs, but not here.

Hello, I planned to support chained storages but for lack of time I didn't implemented that yet.

@darkweak ah, great to hear we're on the same page. I think it should be a nice feature, one which is not provided by common caching solutions that I know of / have used. 👍