cliff42 opened a new issue, #1722: URL: https://github.com/apache/casbin/issues/1722
Would it be possible to make the caching of `GeneratedGFunctions` configurable? Right now, the results of the generated govaluate functions are stored in-memory in a `memorized` map and reused when appropriate to avoid unnecessary calculations. When using policies with wildcard values with a large number of unique matches, or enforcing auth on endpoints that take uuid path params etc. (which each create a new entry in the cache) this map can quickly grow as a new functions are created which uses a lot of memory. Would it be possible to make enabling this configurable, for cases where eating the performance hit is preferable to having a large cache in memory? Thanks! See `GeneratedGFunctions` function here: https://github.com/apache/casbin/blob/017ae0ea04fa5355fbdda91be64ce6df9feac011/util/builtin_operators.go#L405 ``` // GenerateGFunction is the factory method of the g(_, _[, _]) function. func GenerateGFunction(rm rbac.RoleManager) govaluate.ExpressionFunction { memorized := sync.Map{} return func(args ...interface{}) (interface{}, error) { // Like all our other govaluate functions, all args are strings. // Allocate and generate a cache key from the arguments... total := len(args) for _, a := range args { aStr := a.(string) total += len(aStr) } builder := strings.Builder{} builder.Grow(total) for _, arg := range args { builder.WriteByte(0) builder.WriteString(arg.(string)) } key := builder.String() // ...and see if we've already calculated this. v, found := memorized.Load(key) if found { return v, nil } // If not, do the calculation. // There are guaranteed to be exactly 2 or 3 arguments. name1, name2 := args[0].(string), args[1].(string) if rm == nil { v = name1 == name2 } else if len(args) == 2 { v, _ = rm.HasLink(name1, name2) } else { domain := args[2].(string) v, _ = rm.HasLink(name1, name2, domain) } memorized.Store(key, v) return v, nil } } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
