It may look something like this:
 
Map knowledgeBaseCacheMap = new HashMap();
 
this.knowledgeBase = knowledgeBaseCacheMap.get("<SOME_IDENTIFIER>");
 
if(this.knowledgeBase == null){
   this.knowledgeBase.addKnowledgePackages(packages);
   knowledgeBaseCacheMap.put("<SOME_IDENTIFIER>", this.knowledgeBase)
}
 
By doing this the packages get added to the knowledgeBase only for the first time. From second request onwards you get the same knowledgeBase each time without the need for adding the packages again. 
 
But this is valid only if you are not changing your rules. If your rules are changing from time to time, you may have to look at caching at more lower levels. 
 
I am not sure whether this can be helpful in your case but this is often helpful.
 

Regards,

Rajnikant Gupta
http://rkthinks.wordpress.com/


2010/5/3 Moe Alkhafaji <moe.alkhafaji@medcpu.com>
Thanks for the reply. But I don't understand what you mean by caching the KnowledgeBase. This is about adding a pre compiled KnowledgePackage to a KnowledgeBase. So, how does caching a KnowledgeBase makes addition of new KnowledgePackage faster? Please excuse my ignorance if I am not catching what you are suggesting. Maybe a couple of lines of code to demonstrate your suggestion would be greatly appreciated. Thanks. 

Sent from my iPhone

On May 3, 2010, at 1:24 AM, Rajnikant Gupta <capricorn.raj@gmail.com> wrote:

Hi,
 
Yes, adding packages to knowledgeBase does take some time. You can probably try caching your knowledgeBase. By doing this all, but first, requests should be significantly fast.
 
 
 

Regards,

Rajnikant Gupta

http://rkthinks.wordpress.com/


On Mon, May 3, 2010 at 11:36 AM, malkhafaji <moe.alkhafaji@medcpu.com> wrote:

Hello,

I am trying to add knowledge packages to an existing KnowledgeBase. My
largest DRL file has 110 rules. I noticed that it may take up to 5 seconds
just to execute the following statement:

this.knowledgeBase.addKnowledgePackages(packages);

where "packages" is just a list of one knowledge package representing one
drl. The nature of my rules is that I initially load a small set of rules
and then at runtime my rules may load other DRLs. The problem is each DRL
loading command (this.knowledgeBase.addKnowledgePackages(packages)) takes a
few seconds and I have no idea why. Although, all those DRLs are already
compiled (at startup time). It is the line I pasted above that takes the
longest time out of anything else I do.

Any idea why just merely adding a KnowledgePackage list to a KnowledgeBase
can take this much time? Do you guys have any suggestions on how I can
reduce this time? I tried to create another dummy KnowledgeBase and get the
KnowledgePackage from it at runtime and add that to my KnowedgeBase above
(thinking that would reduce the time maybe), but not at all.

Any ideas would be great. The API does not have much info on what that add
method exactly does behind the scenes, and how I can get around the long
delays. This is very frustrating to me, and I am not sure where to look.
Thanks for ANY help at all.
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/addKnowledgePackages-Delay-tp772574p772574.html
Sent from the Drools - User mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users