github.com/hashicorp/vault/sdk@v0.11.0/helper/keysutil/transit_lru.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package keysutil
     5  
     6  import lru "github.com/hashicorp/golang-lru"
     7  
     8  type TransitLRU struct {
     9  	size int
    10  	lru  *lru.TwoQueueCache
    11  }
    12  
    13  func NewTransitLRU(size int) (*TransitLRU, error) {
    14  	lru, err := lru.New2Q(size)
    15  	return &TransitLRU{lru: lru, size: size}, err
    16  }
    17  
    18  func (c *TransitLRU) Delete(key interface{}) {
    19  	c.lru.Remove(key)
    20  }
    21  
    22  func (c *TransitLRU) Load(key interface{}) (value interface{}, ok bool) {
    23  	return c.lru.Get(key)
    24  }
    25  
    26  func (c *TransitLRU) Store(key, value interface{}) {
    27  	c.lru.Add(key, value)
    28  }
    29  
    30  func (c *TransitLRU) Size() int {
    31  	return c.size
    32  }