From caee9ee5f819c9b86fa8e2e0fd9d77a2ba79dc7f Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期三, 02 八月 2023 14:10:41 +0800 Subject: [PATCH] redis缓存加入内存缓存 --- code_attribute/code_nature_analyse.py | 28 +++++++++++++++++++++++++--- 1 files changed, 25 insertions(+), 3 deletions(-) diff --git a/code_attribute/code_nature_analyse.py b/code_attribute/code_nature_analyse.py index 77d0a4d..4fca075 100644 --- a/code_attribute/code_nature_analyse.py +++ b/code_attribute/code_nature_analyse.py @@ -15,6 +15,8 @@ class CodeNatureRecordManager: __redisManager = RedisManager(0) + __k_format_cache = {} + __nature_cache = {} @classmethod def __get_redis(cls): @@ -32,6 +34,18 @@ return json.loads(val) return None + @classmethod + def get_k_format_cache(cls, code): + val = None + if code in cls.__k_format_cache: + val = cls.__k_format_cache[code] + if not val: + val = cls.get_k_format(code) + if val: + cls.__k_format_cache[code] = val + # 澶嶅埗 + return copy.deepcopy(val) if val else None + # 淇濆瓨鑲℃�� @classmethod def save_nature(cls, code, natures): @@ -43,6 +57,15 @@ if val: return json.loads(val) return None + + @classmethod + def get_nature_cache(cls, code): + if code in cls.__nature_cache: + return cls.__nature_cache[code] + val = cls.get_nature(code) + if val: + cls.__nature_cache[code] = val + return val # 璁剧疆鍘嗗彶K绾� @@ -79,9 +102,8 @@ # 鏄惁鍏锋湁K绾垮舰鎬� def is_has_k_format(limit_up_price, record_datas): - is_too_high, is_new_top, is_lowest, is_near_new_top, is_n, is_v, has_format, volume_info = get_k_format( - float(limit_up_price), - record_datas) + is_too_high, is_new_top, is_lowest, is_near_new_top, is_n, is_v, has_format, volume_info, is_special = get_k_format( + float(limit_up_price), record_datas) if not has_format: return False, "涓嶆弧瓒矺绾垮舰鎬�" return True, "鏈夊舰鎬�" -- Gitblit v1.8.0