Make the cache TTL configurable

This commit is contained in:
2021-12-09 13:40:39 +01:00
parent 167533a65f
commit 440927b2c1
2 changed files with 9 additions and 1 deletions

View File

@@ -36,6 +36,13 @@ class LDAPConnection:
self.__LDAP_FILTER = ldap_setting("FILTER", "")
self.__LDAP_SEARCH_BASE = ldap_setting("SEARCH_BASE", "")
# The time a cache entry is valid (in hours)
try:
self.__LDAP_CACHE_TTL = int(ldap_setting("CACHE_TTL", ""))
except ValueError:
logging.error("Invalid value for cache_ttl. Defaulting to 1 hour")
self.__LDAP_CACHE_TTL = 1
password = ldap_setting("BIND_PW", "")
if not password:
pwfile = ldap_setting("BIND_PW_FILE", "")
@@ -84,7 +91,7 @@ class LDAPConnection:
return False
if len(result) == 1:
self.__user_cache[username] = timezone.now() + timezone.timedelta(hours=1)
self.__user_cache[username] = timezone.now() + timezone.timedelta(hours=self.__LDAP_CACHE_TTL)
return True
return False