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

Cache ruller #96

Merged
merged 6 commits into from
Aug 3, 2023
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ example.json
*.env
*.out
vendor
api.http
6 changes: 6 additions & 0 deletions api.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
POST http://localhost:8000/api/v1/eval/jamie-menu-64623317-d00c-4508-8db3-613d1ed24638/
Content-Type: application/json

{
"idade":13
}
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func LoadConfig() (err error) {
if err2, ok := err.(*os.PathError); !ok {
err = err2
log.Errorf("Error on Load Config: %v", err)

return
}
}
Expand All @@ -102,7 +103,6 @@ func LoadConfig() (err error) {
config.ResolverBridgeHeaders.Set(entries[0], entries[1])
}
}

return
}

Expand Down
22 changes: 18 additions & 4 deletions services/rulles.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,22 @@ func (s Eval) GetKnowledgeBase(knowledgeBaseName string, version string) (*ast.K
existing := s.knowledgeBaseCache[info]

if existing == nil {

var ExpirationDate time.Time

switch s.expirationType {
case "seconds":
ExpirationDate = time.Now().Add(time.Duration(s.expirationMultiplier) * time.Second)
case "minutes":
ExpirationDate = time.Now().Add(time.Duration(s.expirationMultiplier) * time.Minute)
case "hours":
ExpirationDate = time.Now().Add(time.Duration(s.expirationMultiplier) * time.Hour)
}
existing = &knowledgeBaseCache{
KnowledgeBase: s.GetKnowledgeLibrary().GetKnowledgeBase(knowledgeBaseName, version),
ExpirationDate: time.Now().Add(time.Minute * 5),
ExpirationDate: ExpirationDate,
}
s.knowledgeBaseCache[info] = existing

return existing.KnowledgeBase, nil
}
if existing.KnowledgeBase.Version != "latest" && len(existing.KnowledgeBase.RuleEntries) > 0 {
return existing.KnowledgeBase, nil
Expand All @@ -192,7 +201,12 @@ func (s Eval) GetKnowledgeBase(knowledgeBaseName string, version string) (*ast.K
}

loadMutex.Lock()
s.knowledgeLibrary.RemoveRuleEntry(existing.KnowledgeBase.Name, knowledgeBaseName, version)

for key := range existing.KnowledgeBase.RuleEntries {

s.knowledgeLibrary.RemoveRuleEntry(key, knowledgeBaseName, version)
}

err := s.LoadRemoteGRL(knowledgeBaseName, version)
if err != nil {
log.Errorf("Erro on load: %v", err)
Expand Down