diff --git a/cache.go b/cache.go index f42b378..071d075 100644 --- a/cache.go +++ b/cache.go @@ -9,6 +9,7 @@ import ( "net/http" "net/http/httptest" "net/url" + "runtime" "strconv" "strings" "time" @@ -210,6 +211,10 @@ func getCache(key string, next http.Handler, r *http.Request) (item *cacheItem) func purgeCache() { cacheR.Clear() + // Do manual GC + go func() { + runtime.GC() + }() } func setInternalCacheExpirationHeader(w http.ResponseWriter, expiration int) { diff --git a/http.go b/http.go index ec2ed0e..3c7c2ed 100644 --- a/http.go +++ b/http.go @@ -6,6 +6,7 @@ import ( "log" "net/http" "net/url" + "runtime" "strconv" "strings" "sync/atomic" @@ -89,6 +90,11 @@ func reloadRouter() error { } purgeCache() d.swapHandler(h) + // Do manual GC + go func() { + time.Sleep(10 * time.Second) + runtime.GC() + }() return nil }