Fork me on GitHub
#clara
<
2016-07-08
>
raymcdermott06:07:11

To play that back my understanding is that I create an empty session (as in (def empty-session (mk-session))) and insert facts on a per customer basis and fire the rules per customer - I hope that’s what you mean. If not, I would like to understand more!

raymcdermott06:07:53

the issue seems to revolve around cases where side effects or where establishing truth is expensive in complex sessions but I don’t have that issue - my case is very much operating like a pure function where Clara is simply used to improve expressivity

raymcdermott07:07:37

dumb question - are the facts from previous sessions GCd? If not, must I retract them? It would be simpler to take the hit on running mksession every time and TBH I have not profiled that so maybe it’s also not such a biggie!

wparker14:07:09

@raymcdermott: Clara sessions are intended to be data structures that obey Clojure idioms, that is, they are value-based and immutable. When you insert a fact into a session, a new session is returned that is independent of the previous session. So, for example, if you create an empty session and insert a fact into it, the original empty session still exists and can be reused. I created a quick demo of this at https://gist.github.com/WilliamParker/c6be14cb249d55b6d2e3ff42500a9334

wparker14:07:59

The “com/clear-session-cache!” clears a cache of created sessions that Clara automatically creates unless it is explicitly turned off. The sessions without facts are cached by Clara on the set of rules, queries, and session options to save compilation time. However, this cache should never contain sessions with facts. The relevant code for that cache is at https://github.com/rbrush/clara-rules/blob/0.11.1/src/main/clojure/clara/rules/compiler.clj#L1530

wparker14:07:50

Clara should only maintain references to facts through sessions. Once all sessions containing a given fact are GC’able then that fact itself should be GC’able as far as Clara is concerned.

wparker14:07:29

To clarify too, Clara doesn’t copy the facts between sessions that contain them; if you have a session that contains FactA and then you insert FactB in it you’ll have two sessions that both contain a reference to the same FactA object. Clara expects that facts won’t be mutated after insertion.

raymcdermott18:07:17

thanks - I appreciate the effort put into your answer

raymcdermott18:07:50

it’s also nice to see answers from two people that are not @ryanbrush 😉

raymcdermott18:07:26

seriously, I'm a fan and it’s good to see the community growing