Debian Codegraph @

pkg/authentication/token/cache/cache_simple.go

raw
1 /*
2 Copyright 2017 The Kubernetes Authors.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 package cache
18
19 import (
20 "time"
21
22 utilcache "k8s.io/apimachinery/pkg/util/cache"
23 "k8s.io/utils/clock"
24 )
25
26 type simpleCache struct {
27 cache *utilcache.Expiring
28 }
29
30 func newSimpleCache(clock clock.Clock) cache {
31 return &simpleCache{cache: utilcache.NewExpiringWithClock(clock)}
32 }
33
34 func (c *simpleCache) get(key string) (*cacheRecord, bool) {
35 record, ok := c.cache.Get(key)
36 if !ok {
37 return nil, false
38 }
39 value, ok := record.(*cacheRecord)
40 return value, ok
41 }
42
43 func (c *simpleCache) set(key string, value *cacheRecord, ttl time.Duration) {
44 c.cache.Set(key, value, ttl)
45 }
46
47 func (c *simpleCache) remove(key string) {
48 c.cache.Delete(key)
49 }