Archived
1
0

try varnish invalidation with all languages

This commit is contained in:
Jeff Becker 2017-10-17 08:50:47 -04:00
parent 1f24f03cf5
commit 85248787fc
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
2 changed files with 28 additions and 8 deletions

View File

@ -26,6 +26,14 @@ type nullHandler struct {
access sync.Mutex 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 { func (self *nullHandler) GetI18N(r *http.Request) *I18N {
lang := r.URL.Query().Get("lang") lang := r.URL.Query().Get("lang")
if lang == "" { if lang == "" {

View File

@ -17,15 +17,27 @@ type VarnishCache struct {
} }
func (self *VarnishCache) invalidate(r string) { func (self *VarnishCache) invalidate(r string) {
u, _ := url.Parse(r) var langs []string
resp, err := self.client.Do(&http.Request{ langs = append(langs, "")
Method: "PURGE", self.handler.ForEachI18N(func(lang string) {
URL: u, langs = append(langs, lang)
}) })
if err == nil { for _, lang := range langs {
resp.Body.Close() u, _ := url.Parse(r)
} else { if lang != "" {
log.Println("varnish cache error", err) 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)
}
} }
} }