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/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) {

View File

@ -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
}