2023-03-15 16:00:52 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2019-06-04 22:40:56 +00:00
|
|
|
package keysutil
|
|
|
|
|
|
|
|
import lru "github.com/hashicorp/golang-lru"
|
|
|
|
|
|
|
|
type TransitLRU struct {
|
|
|
|
size int
|
|
|
|
lru *lru.TwoQueueCache
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewTransitLRU(size int) (*TransitLRU, error) {
|
|
|
|
lru, err := lru.New2Q(size)
|
|
|
|
return &TransitLRU{lru: lru, size: size}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *TransitLRU) Delete(key interface{}) {
|
|
|
|
c.lru.Remove(key)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *TransitLRU) Load(key interface{}) (value interface{}, ok bool) {
|
|
|
|
return c.lru.Get(key)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *TransitLRU) Store(key, value interface{}) {
|
|
|
|
c.lru.Add(key, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *TransitLRU) Size() int {
|
|
|
|
return c.size
|
|
|
|
}
|