Search code examples
memorydrools

Storing large reference data objects in Drools


I'm looking for a way to store large objects within Drools for long periods of time (i.e. not like facts which are added and removed from within a session).

I've read that Drools works using KnowledgeBases and Sessions (Stateless & Stateful) and that KnowledgeBases contain application knowledge definitions but no runtime data.

In a case where I need to store, for example, a large dictionary (that won't change but will be referenced by more than one successive session), and have objects added to working memory and checked against this dictionary to have rules fired, where would it be best to have this stored?

Does everything just go into working memory (in which case, would I need to load the dictionary into memory each time I open a new session?) or am I just missing a crucial Drools basic principle? Would global variables be a good fix for this?


Solution

  • Not sure how large "large" is (of course there's always a performance tradeoff), but you could also use an inserted object to pull from a database (/cache) and have the rules access the values via method.

     when 
        $y : AnObject (name == "car", lookupPrice > 10000 );
    

    where AnObject.getLookupPrice() is a method that would pull a value out of the cached / stored dictionary.

    If the object isn't too big you could codify as well (as an object) and use it the same way.