Comparison

mod_pubsub_serverinfo/mod_pubsub_serverinfo.lua @ 5828:55b99f593c3a

mod_pubsub_serverinfo: Disco/info cache TTL should be configurable This module caches the disco/info results of remote domains. This commit introduces a new configuration option that allows an admin to configure the cache expiry duration.
author Guus der Kinderen <guus.der.kinderen@gmail.com>
date Thu, 04 Jan 2024 12:05:51 +0100
parent 5827:c3eeeb968403
child 5831:2465d5191ae9
comparison
equal deleted inserted replaced
5827:c3eeeb968403 5828:55b99f593c3a
5 local local_domain = module:get_host(); 5 local local_domain = module:get_host();
6 local service = module:get_option(module.name .. "_service") or "pubsub." .. local_domain; 6 local service = module:get_option(module.name .. "_service") or "pubsub." .. local_domain;
7 local node = module:get_option(module.name .. "_node") or "serverinfo"; 7 local node = module:get_option(module.name .. "_node") or "serverinfo";
8 local actor = module.host .. "/modules/" .. module.name; 8 local actor = module.host .. "/modules/" .. module.name;
9 local publication_interval = module:get_option(module.name .. "_publication_interval") or 300; 9 local publication_interval = module:get_option(module.name .. "_publication_interval") or 300;
10 local cache_ttl = module:get_option(module.name .. "_cache_ttl") or 3600;
10 11
11 local opt_in_reports 12 local opt_in_reports
12 13
13 function module.load() 14 function module.load()
14 discover_node():next( 15 discover_node():next(
211 if query ~= nil then 212 if query ~= nil then
212 for feature in query:childtags("feature", "http://jabber.org/protocol/disco#info") do 213 for feature in query:childtags("feature", "http://jabber.org/protocol/disco#info") do
213 if feature.attr.var == 'urn:xmpp:serverinfo:0' then 214 if feature.attr.var == 'urn:xmpp:serverinfo:0' then
214 opt_in_cache[remoteDomain] = { 215 opt_in_cache[remoteDomain] = {
215 opt_in = true; 216 opt_in = true;
216 expires = os.time() + 3600; 217 expires = os.time() + cache_ttl;
217 } 218 }
218 return; -- prevent 'false' to be cached, down below. 219 return; -- prevent 'false' to be cached, down below.
219 end 220 end
220 end 221 end
221 end 222 end
222 end 223 end
223 opt_in_cache[remoteDomain] = { 224 opt_in_cache[remoteDomain] = {
224 opt_in = false; 225 opt_in = false;
225 expires = os.time() + 3600; 226 expires = os.time() + cache_ttl;
226 } 227 }
227 end, 228 end,
228 function(response) 229 function(response)
229 opt_in_cache[remoteDomain] = { 230 opt_in_cache[remoteDomain] = {
230 opt_in = false; 231 opt_in = false;
231 expires = os.time() + 3600; 232 expires = os.time() + cache_ttl;
232 } 233 }
233 end 234 end
234 ); 235 );
235 236
236 -- return 'false' for now. Better luck next time... 237 -- return 'false' for now. Better luck next time...