File: cache.go

package info (click to toggle)
golang-github-smallstep-crypto 0.63.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,800 kB
  • sloc: sh: 66; makefile: 50
file content (48 lines) | stat: -rw-r--r-- 961 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package tlsutil

import (
	"sync"
)

type credentialsCacheElement struct {
	sni     string
	renewer *Renewer
}

type credentialsCache struct {
	CacheStore *sync.Map
}

func newCredentialsCache() *credentialsCache {
	return &credentialsCache{
		CacheStore: new(sync.Map),
	}
}

func (c *credentialsCache) Load(domain string) (*credentialsCacheElement, bool) {
	v, ok := c.CacheStore.Load(domain)
	if !ok {
		return nil, false
	}
	e, ok := v.(*credentialsCacheElement)
	return e, ok
}

func (c *credentialsCache) Store(domain string, v *credentialsCacheElement) {
	c.CacheStore.Store(domain, v)
}

func (c *credentialsCache) Delete(domain string) {
	c.CacheStore.Delete(domain)
}

func (c *credentialsCache) Range(fn func(domain string, v *credentialsCacheElement) bool) {
	c.CacheStore.Range(func(k, v interface{}) bool {
		if domain, ok := k.(string); ok {
			if e, ok := v.(*credentialsCacheElement); ok {
				return fn(domain, e)
			}
		}
		return true
	})
}