As a part of my project, I am implementing a rule engine based on SpEL and I am trying to make is as efficient as possible. Basically, the engine consists of persisted conditions in SpEL syntax. When an input needs to be evaluated, I query the DB for relevant rules - SpEL expressions, which are run on an EvaluationContext containing the input objects.
I am already using an Ehcache in the application so I wanted to make use of caches in this service as well. EvaluationContext caching is out of question, since the input is different for each request. Caching DB queries is also not that easy because a specific date is a part of the query - different rules are valid in different time.
I thought about caching parsed Expression objects but I have no idea how expensive is to parse an Expression from String and whether the time saved avoiding Expression parsing even makes up for having to query the cache through Spring.
Does anybody know whether it is efficient to use a cache to store parsed Expression objects?
Thanks a lot
You can use SpEL compilation for further optimization.
Take a look at SpEL compilation and Compiler Configuration part in the official documentation of SpEL: https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#expressions-spel-compilation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With