File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,21 +11,32 @@ var cachedAllShortestPaths = make(map[string]graph.Paths)
1111var cachedAllShortestPathLengths = make (map [string ]graph.PathLength )
1212var cacheMu sync.RWMutex
1313
14- // CacheClear clears the cached shortest paths and their lengths.
15- func CacheClear () {
14+ // ClearCache clears the cached shortest paths and their lengths.
15+ func ClearCache () {
1616 cacheMu .Lock ()
1717 defer cacheMu .Unlock ()
1818 cachedAllShortestPaths = make (map [string ]graph.Paths )
1919 cachedAllShortestPathLengths = make (map [string ]graph.PathLength )
2020}
2121
22- // AutoCacheClear starts a goroutine that clears the cache at regular intervals defined by tick.
23- func AutoCacheClear (tick time.Duration ) {
22+ // ClearCacheForGraph clears the cache for a specific graph.
23+ func ClearCacheForGraph (g * graph.Graph ) {
24+ cacheMu .Lock ()
25+ defer cacheMu .Unlock ()
26+
27+ gh := g .Hash ()
28+
29+ delete (cachedAllShortestPaths , gh )
30+ delete (cachedAllShortestPathLengths , gh )
31+ }
32+
33+ // AutoClearCache starts a goroutine that clears the cache at regular intervals defined by tick.
34+ func AutoClearCache (tick time.Duration ) {
2435 go func () {
2536 for {
2637 time .Sleep (tick )
2738
28- CacheClear ()
39+ ClearCache ()
2940 }
3041 }()
3142}
You can’t perform that action at this time.
0 commit comments