-
Notifications
You must be signed in to change notification settings - Fork 24
/
cleaner.go
51 lines (41 loc) · 1.01 KB
/
cleaner.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package httpcache
import (
"sync"
)
const stored_providers_key = "STORED_PROVIDERS_KEY"
const coalescing_key = "COALESCING"
const surrogate_key = "SURROGATE"
type storage_providers struct {
list map[interface{}]bool
sync.RWMutex
}
func newStorageProvider() *storage_providers {
return &storage_providers{
list: make(map[interface{}]bool),
RWMutex: sync.RWMutex{},
}
}
func (s *storage_providers) Add(key interface{}) {
s.RWMutex.Lock()
defer s.RWMutex.Unlock()
s.list[key] = true
}
func (s *SouinCaddyMiddleware) Cleanup() error {
s.logger.Debug("Cleanup...")
td := []interface{}{}
sp, _ := up.LoadOrStore(stored_providers_key, newStorageProvider())
stored_providers := sp.(*storage_providers)
up.Range(func(key, _ interface{}) bool {
if key != stored_providers_key && key != coalescing_key && key != surrogate_key {
if !stored_providers.list[key] {
td = append(td, key)
}
}
return true
})
for _, v := range td {
s.logger.Debugf("Cleaning %v\n", v)
_, _ = up.Delete(v)
}
return nil
}