package requestservice import ( "sync" "time" "github.com/hashicorp/go-version" "edge-infra.dev/pkg/sds/emergencyaccess/types" ) const ( defaultExpiration = 15 * time.Minute ) type versionCache struct { mu sync.RWMutex cache map[types.Target]*version.Version expiration time.Duration } func (c *versionCache) Get(key types.Target) (val *version.Version, ok bool) { c.mu.RLock() defer c.mu.RUnlock() val, ok = c.cache[key] return val, ok } func (c *versionCache) Insert(key types.Target, val *version.Version) { c.mu.Lock() c.cache[key] = val c.mu.Unlock() go func() { time.Sleep(c.expiration) c.Delete(key) }() } func (c *versionCache) Delete(key types.Target) { c.mu.Lock() defer c.mu.Unlock() delete(c.cache, key) }