...
1 package utils_test
2
3 import (
4 "fmt"
5
6 jwtverifier "github.com/okta/okta-jwt-verifier-golang"
7 "github.com/okta/okta-jwt-verifier-golang/utils"
8 )
9
10
11 type ForeverCache struct {
12 values map[string]interface{}
13 lookup func(string) (interface{}, error)
14 }
15
16
17 func (c *ForeverCache) Get(key string) (interface{}, error) {
18 value, ok := c.values[key]
19 if ok {
20 return value, nil
21 }
22 value, err := c.lookup(key)
23 if err != nil {
24 return nil, err
25 }
26 c.values[key] = value
27 return value, nil
28 }
29
30
31 var _ utils.Cacher = (*ForeverCache)(nil)
32
33
34 func NewForeverCache(lookup func(string) (interface{}, error)) (utils.Cacher, error) {
35 return &ForeverCache{
36 values: map[string]interface{}{},
37 lookup: lookup,
38 }, nil
39 }
40
41
42 func Example() {
43 jwtVerifierSetup := jwtverifier.JwtVerifier{
44 Cache: NewForeverCache,
45
46 }
47
48 verifier := jwtVerifierSetup.New()
49 fmt.Println(verifier)
50 }
51
View as plain text