How not to cache http data?

Hello, I do a request to exec_controller and JSONDict.get(str) is always different, but reply_json(X). returns the same result. Only if I restart the server, the result will change. I guess it’s cache, but I’m not sure.
I start the server like this:


This is the code of a program.

:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/http_error)).
:- use_module(library(http/html_write)).
:- use_module(library(http/html_head)).
:- use_module(library(http/http_client)).
:- use_module(library(http/http_parameters)).
:- use_module(library(http/http_session)).
:- use_module(library(http/http_server_files)).
:- use_module(library(pengines)).
:- use_module(library(http/http_json)).
:- use_module(library(http/json_convert)).
:- use_module(library(crypt)).
:- use_module(library(sha)).
:- use_module(library(http/json)).
:- use_module(library(term_to_json)).
:- use_module(functions).
:- use_module(db_users).
:- use_module(user_module).
:- use_module(admin).
:- use_module(graph).

server(Port) :-
        http_server(http_dispatch, [port(Port)]).
stop_server(Port) :-
	http_stop_server(Port, []).

http:location(sapi, root(sapi), []).

:- http_handler(sapi(exec), exec_controller, []).

exec_controller(Request) :-
	http_read_json_dict(Request, JSONDict), !,
	term_to_json(G, X),

There is surely no caching in the HTTP framework. If anything is cached it is probably in parser/2 … Maybe it uses assert/retract to do its work and doesn’t clean?

Yes, you’re absolutely right. I forgot to call retract before starting the program. Thank you.

If you need local assert/retract, typically write your code as

call_cleanup(solve(X), cleanup).

where cleanup uses retractall/1 to reclaim the dynamic predicate clauses involved. For recent versions you can also opt for simply using snapshot/1 which ensures the dynamic database remains unchanged. This also avoids multiple threads interfering. If you do not use snapshot you should use thread_local/1 rather than dynamic/1 as with dynamic/1 two concurrent queries will interfere.