[rules-users] Help with MatchesEvaluatorsDefinition that caches compiled regular expression patterns

Jared Davis sunray at davisprogramming.com
Mon May 4 18:18:39 EDT 2009


I need some help placing a cache of compiled regular expressions using the
MatchesEvaluatorsDefinition as a starting point.

Just for a test I placed a static map in the class:

static Map<String,Pattern> uglyHack = new HashMap<String,Pattern>();


Then in each of the evaluators I have different versions of:

        Pattern p = uglyHack.get(value2);
        if (p == null ) {
            p = Pattern.compile(value2);
            uglyHack.put(value2, p);
        }
        Matcher m = p.matcher(value1);
        return m.matches();

instead of 


        return value1.matches( value2 );


The time elapsed to inserting objects into the workspace has been cut in half.  

.4 seconds -> .2

Has someone already done this "optimization?" Where should the cache be stored?







More information about the rules-users mailing list