-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsession.pl
44 lines (35 loc) · 850 Bytes
/
session.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
%% Procedures for persistent sessions.
:- module(session,
[load/1 % +File
,reload/0
,save/0 % just syncs.
,close/0
,save_fact/3 % +Name, +Value
,get_fact/3 % +Name, -Value
,clear_fact/1
]).
:- use_module(library(persistency)).
:- persistent
fact(name:callable, value:nonvar, seq:nonneg).
load(File) :-
db_attach(File, flush).
% db_sync(reload),
% db_sync(gc).
reload :-
db_sync(reload).
save :-
db_sync(gc).
close :-
db_sync(close).
save_fact(Name, Value, Seq) :-
fact(Name, Value, Seq), !. % already there.
save_fact(Name, Value, Seq) :-
with_mutex(session_db,
(retractall_fact(Name, _, _),
assert_fact(Name, Value, Seq))).
get_fact(Name, Value, Seq) :-
with_mutex(session_db,
(fact(Name, Value, Seq))).
% This is mostly useful for testing.
clear_fact(Name) :-
retractall_fact(Name, _, _).