-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.go
More file actions
31 lines (25 loc) · 694 Bytes
/
cache.go
File metadata and controls
31 lines (25 loc) · 694 Bytes
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
package algorithm
import (
"sync"
"time"
"github.com/elecbug/netkit/graph"
)
var cachedAllShortestPaths = make(map[string]graph.Paths)
var cachedAllShortestPathLengths = make(map[string]graph.PathLength)
var cacheMu sync.RWMutex
// CacheClear clears the cached shortest paths and their lengths.
func CacheClear() {
cacheMu.Lock()
defer cacheMu.Unlock()
cachedAllShortestPaths = make(map[string]graph.Paths)
cachedAllShortestPathLengths = make(map[string]graph.PathLength)
}
// AutoCacheClear starts a goroutine that clears the cache at regular intervals defined by tick.
func AutoCacheClear(tick time.Duration) {
go func() {
for {
time.Sleep(tick)
CacheClear()
}
}()
}