github.com/fortexxx/gqlgen@v0.10.3-0.20191216030626-ca5ea8b21ead/graphql/handler/lru/lru.go (about)

     1  package lru
     2  
     3  import (
     4  	"github.com/99designs/gqlgen/graphql"
     5  	lru "github.com/hashicorp/golang-lru"
     6  )
     7  
     8  type LRU struct {
     9  	lru *lru.Cache
    10  }
    11  
    12  var _ graphql.Cache = &LRU{}
    13  
    14  func New(size int) *LRU {
    15  	cache, err := lru.New(size)
    16  	if err != nil {
    17  		// An error is only returned for non-positive cache size
    18  		// and we already checked for that.
    19  		panic("unexpected error creating cache: " + err.Error())
    20  	}
    21  	return &LRU{cache}
    22  }
    23  
    24  func (l LRU) Get(key string) (value interface{}, ok bool) {
    25  	return l.lru.Get(key)
    26  }
    27  
    28  func (l LRU) Add(key string, value interface{}) {
    29  	l.lru.Add(key, value)
    30  }