goadesign / goa

🌟 Goa: Elevate Go API development! 🚀 Streamlined design, automatic code generation, and seamless HTTP/gRPC support. ✨
https://goa.design
MIT License
5.71k stars 560 forks source link

HTTP cache - RFC compliant with many other features #3274

Closed darkweak closed 1 year ago

darkweak commented 1 year ago

Hello,

I already wrote an HTTP cache system (called Souin) used by the caddy cache-handler module and roadrunner, compatible with Træfik, Tyk and many other reverse-proxies/API Gateway. It supports the RFC-7234, can partially cache graphQL request, invalidate using xkeys/ykeys like Varnish. It also implements the Fastly purge using the Surrogate-key header. It can store and invalidate a CDN (cloudflare, fastly, Akamai), and it supports the Cache-Status RFC directive. It implements two in-memory/fs storages (badger & nutsdb) and two distributed storages (olric & etcd) that are fully configurable. The keys can be tweaked (e.g. serve the same cached css for multiple domains) and we can change the Cache-Status name through the configuration and it support the ESI tags processing. Would you be interested to add that in goa either in the default or in the plugins repository?

Let me know your preference about that. ✌️

raphael commented 1 year ago

Hello, thank you for reaching out, this sounds very interesting. Just to make sure I understand: this would be a HTTP middleware that Goa end users could configure to take advantage of Souin? In particular there wouldn't be a need to modify the code generated by Goa correct?

darkweak commented 1 year ago

@raphael thank you for your answer. In fact I would make it as simple as possible to use for end users but I don't know which one is the best choice between middleware and plugin in Goa to achieve that.

this would be a HTTP middleware that Goa end users could configure to take advantage of Souin

Yep that's it, they could have an HTTP cache proxy with few lines of configuration directly in goa.

raphael commented 1 year ago

Perfect, a HTTP middleware is probably the easiest then. A plugin is only required if code needs to be generated. There would be nothing specific to Goa, just a vanilla Go HTTP middleware (similar to https://github.com/goadesign/goa/blob/v3/http/middleware/trace.go#L35). Maybe the best is to provide an example in the examples repo?

darkweak commented 1 year ago

@raphael Can you review the folder that contains the Goa middleware setup? https://github.com/darkweak/souin/tree/feat/plugins/goa/introduce-new-support/plugins/goa

raphael commented 1 year ago

@darkweak Sorry for the delay, I tried to look for the example but it looks like the branch does not exist anymore.

darkweak commented 1 year ago

Hey 👋, No worries, if you want to check the integration I did, you can refer to the directory here https://github.com/darkweak/souin/tree/master/plugins/goa

I think we can close this issue now 🙂

raphael commented 1 year ago

Looks great, thank you!