open-vault/sdk/helper/keysutil/transit_lru.go
Hamid Ghaf 27bb03bbc0
adding copyright header (#19555)
* adding copyright header

* fix fmt and a test
2023-03-15 09:00:52 -07:00

33 lines
627 B
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
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
}