Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request - Caching #878

Open
rrichardson opened this issue Nov 22, 2016 · 43 comments
Open

Feature Request - Caching #878

rrichardson opened this issue Nov 22, 2016 · 43 comments
Labels
contributor/wanted Participation from an external contributor is highly requested kind/enhancement a new or improved feature. priority/P3 maybe

Comments

@rrichardson
Copy link

It would be nice to have caching without having to add additional moving parts to our infrastructure. Some features I'd like to see : Cache by annotation/self-config. LRU with max memory/item limit. Max duration.

It seems like it would be fairly simple to add a simple LRU caching middleware to Traefik. The tricky part would be the configuration side, being able to specify which paths, duration, max mem, etc..

Has this been discussed?

@emilevauge emilevauge added the kind/enhancement a new or improved feature. label Nov 24, 2016
@errm
Copy link
Contributor

errm commented Nov 28, 2016

Perhaps we could use https://github.com/lox/httpcache

@pascalandy
Copy link
Contributor

Love this, but it might be a pain to maintain.

IMHO, we could use existing caching solution like Varnish and Nginx. I don't know how to configure this at this point (Docker Swarm Mode here). We just need to know how to run this.

Any docker-compose setup anyone ?

@Berndinox
Copy link

+1

@ldez ldez added the priority/P3 maybe label Jun 6, 2017
@voroninman
Copy link

voroninman commented Sep 13, 2017

It seems like it would be fairly simple to add a simple LRU caching middleware to Traefik. The tricky part would be the configuration side, being able to specify which paths, duration, max mem, etc..

@rrichardson As a start a memory limit should be enough to configure such middleware. A HTTP backend can control caching via response headers. Things could go wild when you need to adjust hashing, purging, cookie.

@jsleeio
Copy link

jsleeio commented Sep 13, 2017

👍 to simple caching that just has a single memory limit setting and honours Cache-Control/Edge-Control/Expires. Any more than that would be too complicated and probably better suited to something like Varnish

@pascalandy
Copy link
Contributor

Via a docker stack, it would be nice the have Varnish between the webapp and Traefik.

@jebw
Copy link

jebw commented Sep 14, 2017 via email

@fabiorauber
Copy link

Having cache we could have a Grace Period, in which Traefik would serve static pages even if the backend is down. This would eliminate the need for having Nginx/Varnish in front, at least in my scenario.

@funkyfuture
Copy link
Contributor

just some 2 cents, that would be relevant for my use-cases and may have already been mentioned in some way in a previous post.

  • i'd like to 'microcache' the responses of backends for a short period of time in order to relieve them (mainly when the application itself doesn't cache), e.g.

    • a response to a GET request that resolves as 200 is cached for 5 seconds
    • a response that returns in a 301 is cached for 10 minutes
  • when appropriate (again, mainly 200 responses to GET requests), a cached result is returned to the client when the backends are timing out or return a 50x

  • as i depend on traefik's acme client and tls handling, i cannot use nginx for such caching in front of traefik

  • while putting several nginx instances between traefik and backends implies a bigger scaling footprint; also configuration becomes tedious

@jonashackt
Copy link

jonashackt commented Mar 15, 2018

I would also really really appreciate, if Traefik would be able to cache! Please implement this :)

For the meantime, if you look for a simple but fully working example how to use Nginx as a cache in front of Traefik, have a look at https://github.com/jonashackt/traefik-cache-nginx-spring-boot

@joeldeteves
Copy link

This is a much-needed feature for production environments.

@semtex41
Copy link

I would also like to +1 this feature request.
A single pane for the load balance + caching, that is easy to configure and docker/kubernetes friendly would be a game changer.

@anton-johansson
Copy link

anton-johansson commented Oct 26, 2018

I agree with @joeldeteves. I'm currently testing Traefik without anything in front of it, and preparing for production use, but the cache part is important. With nginx in the front, we can easily handle cache of static content right there.

@pascalandy
Copy link
Contributor

Are we sure Traefik is the right place to do this? Varnish and Nginx do cache out of the box.

Should we instead work on a great docker-compose template that makes those two elements work together in a transparent way?

@anton-johansson
Copy link

I'm definitely not sure about it, but it would be great with a simple way to activate caching directly in the load balancer, just like nginx.

I'm not sure how it would work with a docker service in-between handling the cache, so I'd appreciate any examples or templates for that aswell. As long as it's easy to use I'm happy. :)

@joeldeteves
Copy link

joeldeteves commented Oct 26, 2018

@pascalandy IMO the power of traefik comes from labels. Being able to define caching behavior based on labels would be extremely powerful.

@pascalandy
Copy link
Contributor

I have no idea as well.

I'm not sure how it would work with a docker service in-between handling the cache, so I'd appreciate any examples or templates for that aswell.

@isontheline

This comment has been minimized.

@Raboo
Copy link

Raboo commented Oct 29, 2018

Seriously, enough. This issue is open since 2016. There are a lot of subscribers like me that have notifications turned on. And most comments say the same thing. It is understood that this would be a killer feature, awesome feature, that YOU also want this, etc etc. So I suggest unless you have a PR or something constructive to bring to this discussion, just use the thumbs up on the original post and push the subscribe button to get an update of when this might be closed.

@gp187
Copy link

gp187 commented Apr 17, 2020

Cool feature! Must be configurable by file type, origin, disable logging and passing other header rules

location ~ \.(js|css|png|jpg|jpeg|gif|ico|html|woff|woff2|ttf|svg|eot|otf)$ {
    add_header "Access-Control-Allow-Origin" "*";
    expires 1M;
    access_log off;
    add_header Cache-Control "public";
}```

@PureKrome
Copy link

Yep - originally requested back in 2017 and lots of chat in 2018. Still, no word from the Official Team 😢

Would love some acknowledgement .. even if it is a "nope".

@pascalandy
Copy link
Contributor

pascalandy commented Apr 17, 2020

They decided it's a priority/P3 on on Jun 6, 2017. You can disagree with that priority but you can't say they didn't say anything. They are highly responsive and they can't be highly responsive on every features around.

still, no word from the Official Team. Would love some acknowledgement .. even if it is a "nope".

@PureKrome
Copy link

Sorry @pascalandy - i was meaning via some text/post comment-update. Not just a tag that feels like it's lost in the backlog.

I should have been more verbose with my comment, above. Sorry if that came off as rude :( soz.

@djmaze
Copy link

djmaze commented Apr 17, 2020

Don't know if this helps everyone, but I built a configurable nginx proxy container which can easily be used in in conjunction with Traefik. Set the UPSTREAM env variable to the app URL in your internal (overlay) network, then use the same Host rule as for your app service but with additional PathPrefix or Path rules.

Seems to work flawlessly in my swarms.

@pySilver
Copy link

@PureKrome well its very complex (it's much more than @gp187 code snippet shows). Giving that it's far from being core feature I'm not surprised it's still not there. Just use nginx, varnish or cdn (if possible)

@ronny35
Copy link

ronny35 commented May 19, 2020

Hi,

Is it possible to implement caching fonctionnality ?
For example, like this https://github.com/victorspringer/http-cache

@jayjun jayjun mentioned this issue Jul 3, 2020
@kevtainer
Copy link
Contributor

Greetings! There is a plugin for HTTP caching, while it's file-based, there are certainly opportunities for other implementations to be built which use fast data stores (Redis, Memcached, etc).

https://pilot.traefik.io/plugins/270947801855164928/simple-cache

@darkweak
Copy link

Another plugin will be release soon with better integration based on my cache system called Souin
A minimal version is under development more efficient and as simple as possible to configure.
The full version handles redis, in memory and is easy to introduce your own cache provider since you implement the required interface.
Cf this repository: https://github.com/darkweak/souin

@Roken120
Copy link

Hello, any news for caching ?

@darkweak
Copy link

I'm currently working on the RFC support and shared cache support too. Then I'm waiting for the support of unsafe lib to publish my cache system as plugin

@misaon
Copy link

misaon commented Jan 8, 2021

We solved the caching (via headers) of assets in Traefik for our purposes. We have all the images in "/media/cache" and all the CSS/JS in the "/assets/" folder. Then all you have to do is create more host definition and define custom headers for one of them.

(Traefik sorts route priority by length of rule "DESC")

My app labels:

labels:
    - "traefik.enable=true"
    - "traefik.docker.network=traefik-public"
    # Static content
    - "traefik.http.routers.my-app-static.rule=Host('my-app.com') && PathPrefix(`/assets/`, `/media/cache/`)"
    - "traefik.http.routers.my-app-static.entrypoints=https"
    - "traefik.http.routers.my-app-static.tls=true"
    - "traefik.http.routers.my-app-static.middlewares=cache-headers"
    # Dynamic content
    - "traefik.http.routers.my-app.rule=Host('my-app.com')"
    - "traefik.http.routers.my-app.entrypoints=https"
    - "traefik.http.routers.my-app.tls=true"
    - "traefik.http.services.my-app.loadbalancer.server.port=80"

My Traefik service labels:

labels:
    - traefik.http.middlewares.cache-headers.headers.customresponseheaders.Cache-Control=public,max-age=2592000

You can define your own hosts regex for check jpg, css, js etc.

Works great together with Traefik GZIP middleware! 🚀

@darkweak
Copy link

darkweak commented Jan 8, 2021

@misaon Your solution doesn't fix the Træfik problem that tries to fetch service instead of serving app cache. Then it's not RFC compliant due to missing TTL, Vary and other headers defined in the RFC

@misaon
Copy link

misaon commented Jan 8, 2021

@darkweak sure, this not solve issue for all peoples in this topic, but you can determine assets by route and set them needed headers. This example is for our purposes. We still waiting for RFC implementation on Traefik side.

@darkweak
Copy link

darkweak commented Jan 8, 2021

It'll be implemented as soon as Træfik supports go unsafe library for plugins then I'll submit my cache system as official plugin. ATM it works out of the box as standalone software.

@darkweak
Copy link

darkweak commented Jan 17, 2021

Souin now supports RFC-7234 out of the box. I'm now waiting for the unsafe library support from Træfik side to publish efficient cache system as plugin 🎉

@PureKrome
Copy link

@darkweak wow - the Souin app looks great!

@JaneJeon
Copy link

JaneJeon commented Aug 4, 2021

Just my 2 cents, I’d love Varnish integration with Traefik via some middleware, but I really don’t want the Traefik team to reinvent the wheel and re-implement the caching logic/language/config within Traefik itself!

@darkweak
Copy link

darkweak commented Aug 4, 2021

@JaneJeon it would be supported using Souin as Træfik plugin when they will fix this yaegi issue traefik/yaegi#1172

@darkweak
Copy link

darkweak commented Sep 5, 2021

Hello there, little update about this, Souin is now available as træfik plugin here 🎉. You can now use an efficient HTTP cache system without any changes on your stack.

@ddtmachado ddtmachado self-assigned this May 23, 2022
@yongzhang
Copy link

yongzhang commented Sep 9, 2022

Would love to see this in community edition since it's a really useful and important feature.

@thanhtoan1196
Copy link

any updates?

@tigerblue77
Copy link

tigerblue77 commented Nov 30, 2023

This is an enterprise feature so, unfortunately, it seems that you have to buy Traefik enterprise to get caching functionality. Don't hesitate to tell me if I'm wrong.

@darkweak
Copy link

@tigerblue77 you can use Souin as Træfik plugins (v2/v3), it's free and will stay free forever. https://github.com/darkweak/souin

@nmengin nmengin assigned nmengin and unassigned ddtmachado Dec 4, 2023
@nmengin nmengin added the contributor/wanted Participation from an external contributor is highly requested label Jul 1, 2024
@nmengin nmengin removed their assignment Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor/wanted Participation from an external contributor is highly requested kind/enhancement a new or improved feature. priority/P3 maybe
Projects
None yet
Development

No branches or pull requests