mirror of
https://github.com/alice-lg/alice-lg.git
synced 2024-05-11 05:55:03 +00:00
27 lines
334 B
Go
27 lines
334 B
Go
package caches
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
/*
|
|
Use a least recently used caching strategy:
|
|
Store last access in map, retrieve least recently
|
|
used key.
|
|
*/
|
|
type LRUMap map[string]time.Time
|
|
|
|
func (lrumap LRUMap) LRU() string {
|
|
t := time.Now()
|
|
key := ""
|
|
|
|
for k, v := range lrumap {
|
|
if v.Before(t) {
|
|
t = v
|
|
key = k
|
|
}
|
|
}
|
|
|
|
return key
|
|
}
|