diff --git a/common/config_manager.py b/common/config_manager.py index 9f76ce7ac..c0966321e 100644 --- a/common/config_manager.py +++ b/common/config_manager.py @@ -2,6 +2,7 @@ import time import json +from pymemcache.client.base import Client from pathlib import Path from common.lib.database import Database @@ -17,6 +18,7 @@ class ConfigManager: db = None dbconn = None cache = {} + memcache = None core_settings = {} config_definition = {} @@ -28,7 +30,8 @@ def __init__(self, db=None): self.load_user_settings() # establish database connection if none available - self.db = db + if db: + self.with_db(db) def with_db(self, db=None): """ @@ -43,6 +46,12 @@ def with_db(self, db=None): password=self.get("DB_PASSWORD"), host=self.get("DB_HOST"), port=self.get("DB_PORT"), appname="config-reader") if not db else db + # now we have a database connection, we can initialise the memcached + # client (since the address is stored in the database) + memcache_address = self.get("4cat.memcached_server") + if memcache_address: + self.memcache = Client(memcache_address) + def load_user_settings(self): """ Load settings configurable by the user diff --git a/common/lib/config_definition.py b/common/lib/config_definition.py index c92e7c4be..df768da2f 100644 --- a/common/lib/config_definition.py +++ b/common/lib/config_definition.py @@ -233,6 +233,13 @@ "tooltip": "Sphinx is used for full-text search for collected datasources (e.g., 4chan, 8kun, 8chan) and requires additional setup (see 4CAT wiki on GitHub).", "global": True }, + "4cat.memcached_host": { + "type": UserInput.OPTION_TEXT, + "default": "", + "help": "Memcached server", + "tooltip": "Memcached server address, e.g. 'localhost' or '127.0.0.1:11211. If empty, memcached is not used.", + "global": True + }, "logging.slack.level": { "type": UserInput.OPTION_CHOICE, "default": "WARNING", diff --git a/setup.py b/setup.py index 7eff86382..3c3532618 100644 --- a/setup.py +++ b/setup.py @@ -42,6 +42,7 @@ "psutil~=5.0", "psycopg2~=2.9.0", "pyahocorasick~=1.4.0", + "pymemcache", "PyMySQL~=1.0", "PyTumblr==0.1.0", "requests~=2.27",