mirror of https://github.com/jlelse/GoBlog
Collect garbage after cache clear and reloading router
This commit is contained in:
parent
3877507890
commit
5aa04ba366
5
cache.go
5
cache.go
|
@ -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) {
|
||||||
|
|
6
http.go
6
http.go
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue