traefik / plugin-simplecache

Simple cache plugin middleware caches responses on disk
https://plugins.traefik.io/plugins/628c9ec2ffc0cd18356a97a2/log4-shell
Apache License 2.0
45 stars 11 forks source link

Add rule for caching #13

Open Roken120 opened 3 years ago

Roken120 commented 3 years ago

Hello, Can you add a rule for caching only static file, because he caching all type include php. Thank

Roken120 commented 3 years ago

And can you add an option for cookie free ? (remove all cookie of assets )

schoentoon commented 3 years ago

As far as I can tell from the source (and from setting it up myself and using it). It will actually look at the headers from whatever service it proxies whether it should cache it or not. I set it up with nextcloud and it's only caching static assets like js files and images, as it should. Most likely you have your caching misconfigured elsewhere.

Roken120 commented 3 years ago

In my website he make cache of php file and broke all. we can not define the ressource extension to caching ?

unamedplayer commented 3 years ago

I had an issue with PHP, schoentoon is right that simplecache looks at the caching rules of the remote server to decide what to cache and what not to cache. I actually pulled the module they use for this and it seems to interpret caching headers in a funny way (and you can't really blame it because there's a myriad of caching headers who I bet aren't honored the same accross the board).

In any case, I was able to exclude PHP caching on my server (which percolates up to simplecache without having to tweak it). It's already the case but the module simplecache uses needs to see this header: Cache-Control "max-age=0, no-cache, no-store, must-revalidate" no-store is the important one.

I use the following .htaccess to give it absolutely every "no-cache" header one can find in the wild :)

<filesMatch "\.(php)$">
  FileETag None
  <ifModule mod_headers.c>
     Header unset ETag
     Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
     Header set Pragma "no-cache"
     Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
  </ifModule>
</filesMatch>

You might need to enable "header" module for Apache if it isn't already. I hope this helps.

darkweak commented 3 years ago

Hi @unamedplayer if you want a tool with an API which respect the RFC-7234 + Cache-Status and other cool features, take a look at Souin. It will be suported as Træfik plugin asap. Otherwise it works well with traefik (and it's designed to work with) out of the box.