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
})
}
|