9aa4662cec
* transit cache is an Interface implemented by wrapped versions of syncmap and golang-lru * transit cache is an Interface implemented by wrapped versions of syncmap and golang-lru * changed some import paths to point to sdk * Apply suggestions from code review Co-Authored-By: Lexman42 <Lexman42@users.noreply.github.com> * updates docs with information on transit/cache-config endpoint * updates vendored files * fixes policy tests to actually use a cache where expected and renames the struct and storage path used for cache configurations to be more generic * updates document links * fixed a typo in a documentation link * changes cache_size to just size for the cache-config endpoint
30 lines
557 B
Go
30 lines
557 B
Go
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
|
|
}
|