iris icon indicating copy to clipboard operation
iris copied to clipboard

[FEATURE REQUEST] Add an HTTP cache middleware

Open darkweak opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe. Hello, I think having an HTTP cache to not let the users implement by themselves and maintain this code could be good. With that, they could use the default iris distribution, cache the responses and serve that cached response before any other business logic. It will respect the full RFC with new ones (the cache-status and the targeted cache-control RFCs).

Describe the solution you'd like I already wrote a middleware for caddy (https://github.com/caddyserver/cache-handler) and other reverse-proxies/http-servers/APIM and it's based on the Souin HTTP cache project (https://github.com/darkweak/souin). With that it will support the RFC, implement the ESI processor to parse the esi templates and provide an API to manage the cached responses.

Describe alternatives you've considered I didn't find any alternative for that

Additional context I think it will be used like that

  app := iris.New()
  // c is a configuration object
  app.Use(iris.NewHTTPCache(c))

  app.Get("/", func(ctx iris.Context) {
    ctx.HTML("Hello <strong>%s</strong>!", "World")
  })

  app.Listen(":8080")

Let me know about your opinion about that ✌️

darkweak avatar Apr 07 '23 12:04 darkweak

Hello @darkweak,

We have a cache package and examples. However, I see your point. That's totally different and we can implement it for Iris too, it's not so hard (it would take less than 20 minutes as I reviewed the code) but it's not really necessary as you can just use the iris.FromStd function to wrap the SouinCaddyMiddleware.ServeHTTP and register using Use/UseRouter. Tell me if that works for you or we need to think something else please.

kataras avatar Apr 25 '23 19:04 kataras