Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache locally whether issuers have been persisted or not already. #169

Merged
merged 15 commits into from
Aug 23, 2024
5 changes: 4 additions & 1 deletion personalities/sctfe/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type KV struct {
V []byte
}

// TODO(phboneff): replace with AddIssuersIfNotExist
type IssuerStorage interface {
Exists(ctx context.Context, key []byte) (bool, error)
AddIssuers(ctx context.Context, kv []KV) error
Expand Down Expand Up @@ -95,7 +96,7 @@ func (cts *CTStorage) AddIssuerChain(ctx context.Context, chain []*x509.Certific
// Only up to N keys will be stored locally.
// TODO(phboneff): add monitoring for the number of keys
type cachedIssuerStorage struct {
sync.Mutex
sync.RWMutex
m map[string]struct{}
N int // maximum number of entries allowed in m
s IssuerStorage
Expand All @@ -104,7 +105,9 @@ type cachedIssuerStorage struct {
// Exists checks if the key exists in the local cache, if not checks in the underlying storage.
// If it finds it there, caches the key locally.
func (c *cachedIssuerStorage) Exists(ctx context.Context, key []byte) (bool, error) {
phbnf marked this conversation as resolved.
Show resolved Hide resolved
c.RLock()
_, ok := c.m[string(key)]
c.RLock()
phbnf marked this conversation as resolved.
Show resolved Hide resolved
if ok {
klog.V(2).Infof("Exists: found %q in local key cache", key)
return true, nil
Expand Down
Loading