In OgnlUtil.java, when the enableExpressionCache is set to true, the compile(String expression) method will store all expressions in the ConcurrentHashMap. However, applications may have a huge number of expressions which will start to have a huge impact on the Java Heap size because there is no top-limit to this ConcurrentHashMap.
And we cannot simply set enableExpressionCache to false, because the performance of compiling OGNL Expressions upon each usage is massive as well.
We need this to be a Cache (ehcache would work) where the cache has a configurable maximum size. This would provide the benefits of the caching but also would not allow the OGNLUtil.java class to hog the heap.
Some potential expression caching strategies:
- only cache expressions when compilation takes more than X ms (X can be configurable)
- provide a JMX bean to allow purging the cache without restarting the application (can be scheduled when the application is not too much used)
- cache a limited number of expressions (older expression is removed first)