Collect garbage after cache clear and reloading router

This commit is contained in:
Jan-Lukas Else 2021-03-12 08:57:40 +01:00
parent 3877507890
commit 5aa04ba366
2 changed files with 11 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import (
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"net/url" "net/url"
"runtime"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -210,6 +211,10 @@ func getCache(key string, next http.Handler, r *http.Request) (item *cacheItem)
func purgeCache() { func purgeCache() {
cacheR.Clear() cacheR.Clear()
// Do manual GC
go func() {
runtime.GC()
}()
} }
func setInternalCacheExpirationHeader(w http.ResponseWriter, expiration int) { func setInternalCacheExpirationHeader(w http.ResponseWriter, expiration int) {

View File

@ -6,6 +6,7 @@ import (
"log" "log"
"net/http" "net/http"
"net/url" "net/url"
"runtime"
"strconv" "strconv"
"strings" "strings"
"sync/atomic" "sync/atomic"
@ -89,6 +90,11 @@ func reloadRouter() error {
} }
purgeCache() purgeCache()
d.swapHandler(h) d.swapHandler(h)
// Do manual GC
go func() {
time.Sleep(10 * time.Second)
runtime.GC()
}()
return nil return nil
} }