From 44cfd03cee3e1157faf984c42c8f1d29af015c7d Mon Sep 17 00:00:00 2001 From: nineven Date: Fri, 4 Feb 2022 21:33:24 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E9=85=8D=E7=BD=AE=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E8=BF=87=E6=9C=9F=E6=97=B6=E9=97=B430=E5=A4=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fir_ser/api/management/commands/expire_config_caches.py | 5 ++++- fir_ser/api/tasks.py | 4 ++-- fir_ser/api/utils/sysconfig.py | 6 +++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/fir_ser/api/management/commands/expire_config_caches.py b/fir_ser/api/management/commands/expire_config_caches.py index c24f4c3..aaab17e 100644 --- a/fir_ser/api/management/commands/expire_config_caches.py +++ b/fir_ser/api/management/commands/expire_config_caches.py @@ -6,5 +6,8 @@ from api.tasks import clean_config_cache class Command(BaseCommand): help = 'Expire config caches' + def add_arguments(self, parser): + parser.add_argument('key', nargs='?', type=str, default='*') + def handle(self, *args, **options): - clean_config_cache() + clean_config_cache(options.get('key', '*')) diff --git a/fir_ser/api/tasks.py b/fir_ser/api/tasks.py index b415a60..016afda 100644 --- a/fir_ser/api/tasks.py +++ b/fir_ser/api/tasks.py @@ -86,8 +86,8 @@ def start_api_sever_do_clean(): invalid_config_cache() -def clean_config_cache(): - invalid_config_cache() +def clean_config_cache(key): + invalid_config_cache(key) @app.task diff --git a/fir_ser/api/utils/sysconfig.py b/fir_ser/api/utils/sysconfig.py index b949809..f762c9c 100644 --- a/fir_ser/api/utils/sysconfig.py +++ b/fir_ser/api/utils/sysconfig.py @@ -22,8 +22,8 @@ class SystemConfigSerializer(serializers.ModelSerializer): fields = "__all__" -def invalid_config_cache(): - SystemConfigCache('*').del_many() +def invalid_config_cache(key='*'): + SystemConfigCache(key).del_many() # def make_json_value(value, default): @@ -57,7 +57,7 @@ class ConfigCacheBase(object): if d_key != key and data is not None: db_data['value'] = data db_data['key'] = key - cache.set_storage_cache(db_data, timeout=0) + cache.set_storage_cache(db_data, timeout=60 * 60 * 24 * 30) return db_data.get('value') def set_value(self, key, value):