K, value V) (evicted bool) { // Check for existing item if ent, ok := c.items[key]; ok { c.evictList.MoveToFront(ent) ent.Value = value return false } // Add new item … } Mapʹ͕͋Δ͔֬ೝ Listͷઌ಄ʹҠಈ
with 10ms TTL and 5 max keys cache := expirable.NewLRU[string, string](5, nil, time.Millisecond*10) // set value under key1. cache.Add("key1", "val1") // wait for cache to expire time.Sleep(time.Millisecond * 12) // get value under key1 after key expiration r, ok = cache.Get("key1") fmt.Printf("value after expiration is found: %v, value: %q\n", ok, r) } TTLΛ͑ΔͷΛͭ Entry͕আ͞Ε͍ͯΔ