[rules-users] How does 'from' cache works?

Wolfgang Laun wolfgang.laun at gmail.com
Thu Sep 13 01:58:01 EDT 2012


On 12/09/2012, Esteban Aliverti <esteban.aliverti at gmail.com> wrote:
> Assuming I have the following rule:
>
> global SomeClient client;
>
> rule "Poll Values"
> timer (int: 0s 1s)
> when
>     $data: Data() from client.getData();
> then
>     insert($data);
> end
>
> and that I'm just creating a session with just that rule, setting the
> global and calling fireAllRules(). And let's say that my session is running
> for 5 seconds.
>
> My questions are:
> 1.- How many times is the rule going to be executed?

This depends on the condition remaining true after its initial and
only evaluation.

> 2.- How many times is  client.getData() going to be invoked?

Once: client never changes, or art least there is no way to inform the
Engine about a change. "from" followed by something in a fact would be
different.

>
> The test I have shows that the rule is executed 5 times,
> but client.getData() is only invoked for the first activation. The returned
> object is used in the subsequent activations. Is this the expected
> behavior?

Yes.

> As the rule name states, I'm expecting to get some (different) values from
> client every second.
> I understand that I'm doing 'strange' things since the rule doesn't use any
> real fact but I would like to understand why I'm experiencing the described
> behavior.
>

I hope it's clear now.

-W

> Best Regards,
>
>
> XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
>
> Esteban Aliverti
> - Blog @ http://ilesteban.wordpress.com
>


More information about the rules-users mailing list