Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Commit

Permalink
fix: cache key
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphg6 committed Jun 7, 2024
1 parent 88a7289 commit 8f9c819
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions services/rulles.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ var EvalService IEval = NewEval(config.GetConfig())
// - knowledgeLibrary - `knowledgeLibrary` is a pointer to an `ast.KnowledgeLibrary` object. Itis a property of the `Eval` struct.
type Eval struct {
knowledgeLibrary *ast.KnowledgeLibrary
expirationMap map[knowledgeBaseInfo]time.Time
expirationMap map[string]time.Time
versionTTL int64
}

// NewEval creates a new instance of the Eval struct with an empty knowledge library.
func NewEval(config *config.Config) Eval {
return Eval{
knowledgeLibrary: ast.NewKnowledgeLibrary(),
expirationMap: map[knowledgeBaseInfo]time.Time{},
expirationMap: map[string]time.Time{},
versionTTL: config.KnowledgeBaseVersionTTL,
}
}
Expand Down Expand Up @@ -165,7 +165,7 @@ func (s Eval) GetKnowledgeBase(knowledgeBaseName string, version string) (*ast.K
getMutex.Lock()
defer getMutex.Unlock()

info := knowledgeBaseInfo{KnowledgeBaseName: knowledgeBaseName, Version: version}
info := fmt.Sprintf("%s-%s", knowledgeBaseName, version)

base := s.GetKnowledgeLibrary().GetKnowledgeBase(knowledgeBaseName, version)

Expand All @@ -180,9 +180,12 @@ func (s Eval) GetKnowledgeBase(knowledgeBaseName string, version string) (*ast.K

// If the version isn't expired and there are rules, we must retrieve the version
if !expired && len(base.RuleEntries) > 0 {
log.Trace("Eval with cached Knowledge")
return base, nil
}

log.Trace("Start load Knowledge")

loadWg.Add(1)
defer loadWg.Done()

Expand Down Expand Up @@ -283,7 +286,7 @@ func (s Eval) Eval(ctx *types.Context, knowledgeBase *ast.KnowledgeBase) (result
return
}

func (s Eval) isKnowledgeBaseVersionExpired(info knowledgeBaseInfo) bool {
func (s Eval) isKnowledgeBaseVersionExpired(info string) bool {

expireDate, ok := s.expirationMap[info]

Expand Down

0 comments on commit 8f9c819

Please sign in to comment.