add clear cache
This commit is contained in:
+12
-19
@@ -144,7 +144,8 @@ func NewPM(confFp string) (*ProxyManager, error) {
|
||||
pm.Cache = NewQueueMap()
|
||||
pm.applyWeight()
|
||||
// go pm.keepClearingCache()
|
||||
go pm.dynamicWeightLoader()
|
||||
pm.dynamicWeightLoader()
|
||||
pm.listenToClearCache()
|
||||
return &pm, nil
|
||||
}
|
||||
func (pm *ProxyManager) DescribeLoadBalanceMode() string {
|
||||
@@ -227,24 +228,16 @@ func (pm *ProxyManager) Get(addr string) (string, bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// func (pm *ProxyManager) ClearCache() {
|
||||
// // fmt.Println("clearing cache")
|
||||
// pm.mux.Lock()
|
||||
// pm.Cache = New()
|
||||
// pm.mux.Unlock()
|
||||
// // fmt.Println("after:", pm.Cache)
|
||||
// }
|
||||
|
||||
// func (pm *ProxyManager) keepClearingCache() {
|
||||
// interval := pm.CacheCleanInterval
|
||||
// if interval <= 0 {
|
||||
// return
|
||||
// }
|
||||
// for {
|
||||
// time.Sleep(time.Duration(interval) * time.Second)
|
||||
// pm.ClearCache()
|
||||
// }
|
||||
// }
|
||||
func (pm *ProxyManager) listenToClearCache() {
|
||||
sigs := make(chan os.Signal, 1)
|
||||
signal.Notify(sigs, syscall.SIGUSR2, syscall.SIGTERM)
|
||||
go func() {
|
||||
<-sigs
|
||||
pm.mux.Lock()
|
||||
pm.Cache = NewQueueMap()
|
||||
pm.mux.Unlock()
|
||||
}()
|
||||
}
|
||||
|
||||
func (pm *ProxyManager) dynamicWeightLoader() {
|
||||
sigs := make(chan os.Signal, 1)
|
||||
|
||||
Reference in New Issue
Block a user