changeset 5805: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
parents c3eeeb968403
children d4612e7f6724
files mod_pubsub_serverinfo/README.markdown mod_pubsub_serverinfo/mod_pubsub_serverinfo.lua
diffstat 2 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mod_pubsub_serverinfo/README.markdown	Thu Jan 04 11:59:35 2024 +0100
+++ b/mod_pubsub_serverinfo/README.markdown	Thu Jan 04 12:05:51 2024 +0100
@@ -41,3 +41,9 @@
 is 300 seconds (5 minutes). To change this simply put in the config:
 
     pubsub_serverinfo_publication_interval = 180 -- or any other number of seconds
+
+To detect if remote domains allow their domain name to be included in the data that this module publishes, this module will perform a service
+discovery request to each remote domain. To prevent a continuous flood of disco/info requests, the response to these requests is cached. By default,
+a cached value will remain in cache for one hour. This duration can be modified by adding this configuration option:
+
+    pubsub_serverinfo_cache_ttl = 1800 -- or any other number of seconds
--- a/mod_pubsub_serverinfo/mod_pubsub_serverinfo.lua	Thu Jan 04 11:59:35 2024 +0100
+++ b/mod_pubsub_serverinfo/mod_pubsub_serverinfo.lua	Thu Jan 04 12:05:51 2024 +0100
@@ -7,6 +7,7 @@
 local node = module:get_option(module.name .. "_node") or "serverinfo";
 local actor = module.host .. "/modules/" .. module.name;
 local publication_interval = module:get_option(module.name .. "_publication_interval") or 300;
+local cache_ttl = module:get_option(module.name .. "_cache_ttl") or 3600;
 
 local opt_in_reports
 
@@ -213,7 +214,7 @@
 						if feature.attr.var == 'urn:xmpp:serverinfo:0' then
 							opt_in_cache[remoteDomain] = {
 								opt_in = true;
-								expires = os.time() + 3600;
+								expires = os.time() + cache_ttl;
 							}
 							return; -- prevent 'false' to be cached, down below.
 						end
@@ -222,13 +223,13 @@
 			end
 			opt_in_cache[remoteDomain] = {
 				opt_in = false;
-				expires = os.time() + 3600;
+				expires = os.time() + cache_ttl;
 			}
 		end,
 		function(response)
 			opt_in_cache[remoteDomain] = {
 				opt_in = false;
-				expires = os.time() + 3600;
+				expires = os.time() + cache_ttl;
 			}
 		end
 	);