mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-06 03:18:03 +02:00
use expirable cache
This commit is contained in:
parent
f68040be85
commit
cfa929f77f
1 changed files with 4 additions and 5 deletions
|
@ -3,7 +3,9 @@ package evaluator
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/hashicorp/golang-lru/v2/expirable"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
lru "github.com/hashicorp/golang-lru/v2"
|
lru "github.com/hashicorp/golang-lru/v2"
|
||||||
"github.com/open-policy-agent/opa/rego"
|
"github.com/open-policy-agent/opa/rego"
|
||||||
|
@ -15,16 +17,13 @@ import (
|
||||||
// A RegoCompiler compiles rego scripts.
|
// A RegoCompiler compiles rego scripts.
|
||||||
type RegoCompiler struct {
|
type RegoCompiler struct {
|
||||||
Store *store.Store
|
Store *store.Store
|
||||||
policyCache *lru.Cache[string, rego.PreparedEvalQuery]
|
policyCache *expirable.LRU[string, rego.PreparedEvalQuery]
|
||||||
headersCache *lru.Cache[string, rego.PreparedEvalQuery]
|
headersCache *lru.Cache[string, rego.PreparedEvalQuery]
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRegoCompiler creates a new RegoCompiler using the given store.
|
// NewRegoCompiler creates a new RegoCompiler using the given store.
|
||||||
func NewRegoCompiler(store *store.Store) *RegoCompiler {
|
func NewRegoCompiler(store *store.Store) *RegoCompiler {
|
||||||
policyCache, err := lru.New[string, rego.PreparedEvalQuery](10_000)
|
policyCache := expirable.NewLRU[string, rego.PreparedEvalQuery](10_000, nil, time.Hour*24)
|
||||||
if err != nil {
|
|
||||||
panic(fmt.Errorf("failed to create lru cache for policy rego scripts: %w", err))
|
|
||||||
}
|
|
||||||
headersCache, err := lru.New[string, rego.PreparedEvalQuery](1)
|
headersCache, err := lru.New[string, rego.PreparedEvalQuery](1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Errorf("failed to create lru cache for headers rego scripts: %w", err))
|
panic(fmt.Errorf("failed to create lru cache for headers rego scripts: %w", err))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue