Expression Cache in async multi-threaded environment
Opened this issue · 1 comments
Sorry, not really a bug. I just need advice.
I would like to use Expressive in an async multi-threaded environment. Can you please let me know if the compiled expression cache is safe to use in this scenario?
I have run into this problem with NCalc and have to disable caching which is not ideal as I tend to have a high number of repeated expressions.
Regardless I will probably switch to Expressive now that I have found you guys.
Thank you for your efforts.
Hi @codermrrob
I do currently use Expressive in a multi-threaded environment however I do not currently cache the expressions. I do currently suspect there could be some edge cases where it could potentially fail however I am happy to address these.
Some potential issues or points are:
- The main edge case is around when the expression is compiled and the lack of any kind of
lock
ing. This is an easy fix though. - Another point to note is that currently some keywords such as #now# or #today# are evaluated when the expression is compiled and not re-evaluated each time the expression is evaluated. This is the main reason that I do not currently cache the expressions and I cannot seem to decide if this is correct behaviour or not.
- I have also been considering adding in direct support for the TPL (e.g. async/await). Is this what you are referring to with an async multi-threaded environment and do you think it would be of value?
- Are you able to explain what the issues are that you have seen with NCalc? They could well be pitfalls we have also fallen in to on this project but always happy to fix and learn :).
And thank you for considering to use Expressive :).