Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions internal/policy/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package cache
import (
"context"
"sync"

log "github.com/sirupsen/logrus"
)

// policyCacheKey is the key for PolicyCache values in Context.
Expand Down Expand Up @@ -72,25 +70,15 @@ func (c *PolicyCache) Set(key string, value string, err error) {
}

// NewPolicyCache creates and returns a new PolicyCache instance.
func NewPolicyCache(ctx context.Context) (*PolicyCache, error) {
func NewPolicyCache(ctx context.Context) *PolicyCache {
cache, ok := ctx.Value(policyCacheKey).(*PolicyCache)
if ok && cache != nil {
return cache, nil
}

c, err := CreatePolicyCache()
if err != nil {
log.Debug("Failed to create PolicyCache")
return nil, err
return cache
}

return c, nil
}

func CreatePolicyCache() (*PolicyCache, error) {
return &PolicyCache{
Data: sync.Map{},
}, nil
}
}

// PolicyCacheFromContext retrieves the PolicyCache from the context.
Expand Down
Loading
Loading