...
1 package lru
2
3 import (
4 "context"
5
6 lru "github.com/hashicorp/golang-lru/v2"
7
8 "github.com/99designs/gqlgen/graphql"
9 )
10
11 type LRU struct {
12 lru *lru.Cache[string, any]
13 }
14
15 var _ graphql.Cache = &LRU{}
16
17 func New(size int) *LRU {
18 cache, err := lru.New[string, any](size)
19 if err != nil {
20
21
22 panic("unexpected error creating cache: " + err.Error())
23 }
24 return &LRU{cache}
25 }
26
27 func (l LRU) Get(ctx context.Context, key string) (value interface{}, ok bool) {
28 return l.lru.Get(key)
29 }
30
31 func (l LRU) Add(ctx context.Context, key string, value interface{}) {
32 l.lru.Add(key, value)
33 }
34
View as plain text