How can I remove (with PHP) the cache items of only specific hostname?

Does the files have structure I can use for this kind of need?

If you’re using http.cache, according to the documentation at GitHub - nicolasazrak/caddy-cache: Caching middleware for caddy, removal of cached content is still a planned feature with no projected implementation date.

Yes I saw that but I want to write a solution for myself and manage it with PHP (to build API for myself).
I will just send something like
and it will delete all files cached with this name or under this folder.

If you’re able to write your own solution, of course, the functionality is entirely up to you and how you implement it. You might head over to the nicolasazrak/caddy-cache repo and talk to the author about contributing to the existing plugin, or perhaps fork it and complete the modifications yourself.

If it were me, I’d probably be using something that already has this kind of functionality, though - maybe Varnish cache with its flexible VCL.

Can I work with “Varnish cache” with Caddy? because I need Caddy SSL solution

Varnish won’t integrate directly into Caddy, but it’s usually deployed between the SSL terminating proxy/load balancer and an upstream content server.

Caddy can serve both of the latter roles, possibly even at the same time on the same host.

With two Caddies, deploy one as an SSL terminator, sending all traffic to Varnish:

http://, https:// {
  proxy / varnish
  tls {
    max_certs 20

Configure Varnish appropriately, configuring your second Caddy as the upstream content server.

Since Caddy 0.10.12, if you share the ACME folder locally between the two Caddies, an ACME challenge initiated by the Caddy upstream can be fulfilled by the SSL terminating Caddy at the edge (thanks to improved Automatic HTTPS in a cluster), so you won’t even need to specially configure the second Caddy, just use what you’re using now.

Alternately, just have the same Caddy serving as the edge AND upstream server, by adding your site definitions on a different port and configuring Varnish to proxy back to that port as appropriate, e.g.:

http://, https:// {
  proxy / varnish
  tls {
    max_certs 20
} {
  # ...

The single-instance version is slightly inelegant, in my subjective opinion, because you can no longer effortlessly swap the SSL terminator+Varnish part out and have a fully working edge Caddy until you modify its Caddyfile… But both methods should be quite serviceable, and the benefit of not having to write my own cache implementation and use an industry standard solution is great.

Really thanks with all the info you sent.
I almost did it and finish it but… in Varnish you must set backend as IP and not CNAME with multi IPs so we can’t use it because we use AWS EB.
I also tried NGINX but after I set everything up and running I saw that this feature “proxy_cache_purge” is only available on the commercial version (that cost 2.5K per year).
So… it’s looks like I’m going to test all cache server out there or the cache plugin in Caddy will update soon :slight_smile:

If someone have any solution for me it will be great. THX!

Wait, are you saying you can’t define a backend by domain name (because that’s possible), or that it’s not working because it’s not detecting CNAME records, only A records?

Because even with a CNAME, it should resolve down to an IP address just fine…

Yes it’s working with CNAME, but only CNAME that return 1 IP. If the CNAME return 2 IPs it give you an error. Varnish want to be really fast cache service so they resolve the domain before it’s start (it’s all over the web) :slight_smile:

Ahh, so you can’t do DNS load balancing.

That’s rough. Could you do DNS lookups yourself and do templated config generation with the results? Varnish can hot-reload, I believe?

Yes, but then it will slow everything. I’m trying to keep the speed high.

OK good news!
I found a solution (ugly buy still good solution):
I set Caddy → Varnish (for cache) → Nginx (for AWS connect)

That solve all my problem and I hope it will help more people that will see this post :slight_smile:

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.