29 lines
790 B
Go
29 lines
790 B
Go
package util
|
|
|
|
import (
|
|
"forge.cadoles.com/cadoles/bouncer/internal/cache"
|
|
"forge.cadoles.com/cadoles/bouncer/internal/cache/memory"
|
|
)
|
|
|
|
type RuleEngineCache[V any, O any] struct {
|
|
cache cache.Cache[string, *RevisionedRuleEngine[V, O]]
|
|
factory RuleEngineFactoryFunc[V, O]
|
|
}
|
|
|
|
func (c *RuleEngineCache[V, O]) Get(key string) *RevisionedRuleEngine[V, O] {
|
|
revisionedRuleEngine, exists := c.cache.Get(key)
|
|
if !exists {
|
|
revisionedRuleEngine = NewRevisionedRuleEngine(c.factory)
|
|
c.cache.Set(key, revisionedRuleEngine)
|
|
}
|
|
|
|
return revisionedRuleEngine
|
|
}
|
|
|
|
func NewInMemoryRuleEngineCache[V any, O any](factory RuleEngineFactoryFunc[V, O]) *RuleEngineCache[V, O] {
|
|
return &RuleEngineCache[V, O]{
|
|
factory: factory,
|
|
cache: memory.NewCache[string, *RevisionedRuleEngine[V, O]](),
|
|
}
|
|
}
|