Purge removes request data stored for longer than maxAge, in seconds. It returns the amount of requests removed. If maxAge <= 0, all request data is removed. This is only used for sanity check: in case context cleaning was not properly set some request data can be kept forever, consuming an increa
(maxAge int)
| 110 | // amount of memory. In case this is detected, Purge() must be called |
| 111 | // periodically until the problem is fixed. |
| 112 | func Purge(maxAge int) int { |
| 113 | mutex.Lock() |
| 114 | count := 0 |
| 115 | if maxAge <= 0 { |
| 116 | count = len(data) |
| 117 | data = make(map[*http.Request]map[interface{}]interface{}) |
| 118 | datat = make(map[*http.Request]int64) |
| 119 | } else { |
| 120 | min := time.Now().Unix() - int64(maxAge) |
| 121 | for r := range data { |
| 122 | if datat[r] < min { |
| 123 | clear(r) |
| 124 | count++ |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | mutex.Unlock() |
| 129 | return count |
| 130 | } |
| 131 | |
| 132 | // ClearHandler wraps an http.Handler and clears request values at the end |
| 133 | // of a request lifetime. |
nothing calls this directly
no test coverage detected
searching dependent graphs…