The mis-named “tabling” module (should really be called “memoize”) now allows for persisting memoized calls to a file. See:
(docs up on the pldoc server soon).
To see how this works, consider the transitive closure of the subclass/2 fact, as defined in the ontol_db schema:
if you end up using a predicate such as this frequently in one session, you can do this at the start of the session
init :- table_pred(ontol_db:subclassT/2).
This rewrites subclassT/2 behind the scenes. See the code for details.
After loading some subclass/2 facts (e.g. from GO), you then call:
forall(subclassT('GO:0006915',X), writeln(X)). % all ancestors of apoptosis
The first time you call this, the original code is called. The second time you call this, it checks to see if it knows the answer for ‘GO:0006915’ – it does – it then returns the previously calculated results, which have been asserted to memory.
However, this caching is lost when the prolog db is destroyed at the end of the session. Now you can persist this:
The first time this is called, cache.pl is created. All results of subclassT/2 calls are saved there.
After the session the file is retained. In future sessions, if this is called again, the cache is loaded into memory and appended with the results of future calls.
In future, the module may also be extended to be made ‘hookable’, with hooks provided for caching to a relational database.