From 85248787fceeaf1a1f2dbf8108bed1f4b7788fa2 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Tue, 17 Oct 2017 08:50:47 -0400 Subject: [PATCH] try varnish invalidation with all languages --- .../backends/srndv2/src/srnd/null_cache.go | 8 ++++++ .../backends/srndv2/src/srnd/varnish_cache.go | 28 +++++++++++++------ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/contrib/backends/srndv2/src/srnd/null_cache.go b/contrib/backends/srndv2/src/srnd/null_cache.go index 1e03daa..06991ef 100644 --- a/contrib/backends/srndv2/src/srnd/null_cache.go +++ b/contrib/backends/srndv2/src/srnd/null_cache.go @@ -26,6 +26,14 @@ type nullHandler struct { access sync.Mutex } +func (self *nullHandler) ForEachI18N(v func(string)) { + self.access.Lock() + for lang := range self.i18n { + v(lang) + } + self.access.Unlock() +} + func (self *nullHandler) GetI18N(r *http.Request) *I18N { lang := r.URL.Query().Get("lang") if lang == "" { diff --git a/contrib/backends/srndv2/src/srnd/varnish_cache.go b/contrib/backends/srndv2/src/srnd/varnish_cache.go index 3a23723..820828f 100644 --- a/contrib/backends/srndv2/src/srnd/varnish_cache.go +++ b/contrib/backends/srndv2/src/srnd/varnish_cache.go @@ -17,15 +17,27 @@ type VarnishCache struct { } func (self *VarnishCache) invalidate(r string) { - u, _ := url.Parse(r) - resp, err := self.client.Do(&http.Request{ - Method: "PURGE", - URL: u, + var langs []string + langs = append(langs, "") + self.handler.ForEachI18N(func(lang string) { + langs = append(langs, lang) }) - if err == nil { - resp.Body.Close() - } else { - log.Println("varnish cache error", err) + for _, lang := range langs { + u, _ := url.Parse(r) + if lang != "" { + q := u.Query() + q.Add("lang", lang) + u.RawQuery = q.Encode() + } + resp, err := self.client.Do(&http.Request{ + Method: "PURGE", + URL: u, + }) + if err == nil { + resp.Body.Close() + } else { + log.Println("varnish cache error", err) + } } }