File tree Expand file tree Collapse file tree 4 files changed +52
-4
lines changed
Expand file tree Collapse file tree 4 files changed +52
-4
lines changed Original file line number Diff line number Diff line change @@ -19,4 +19,14 @@ APP_PORT = 8088
1919APP_DEBUG = true
2020# flask-compress压缩配置
2121APP_COMPRESS_ALGORITHM = ' br'
22- APP_COMPRESS_BR_LEVEL = 11
22+ APP_COMPRESS_BR_LEVEL = 11
23+
24+ # -------- 缓存配置 --------
25+ # LRU缓存的限制数量,0表示无限制
26+ LRU_CACHE_MAXSIZE = 10000
27+ # LRU缓存不重新分配的容量
28+ LRU_CACHE_CAPACITY = 10000
29+ # TTL缓存的限制数量,0表示无限制
30+ TTL_CACHE_MAXSIZE = 0
31+ # TTL缓存过期时间(秒)
32+ TTL_CACHE_EXPIRE = 600
Original file line number Diff line number Diff line change @@ -19,4 +19,14 @@ APP_PORT = 8088
1919APP_DEBUG = false
2020# flask-compress压缩配置
2121APP_COMPRESS_ALGORITHM = ' br'
22- APP_COMPRESS_BR_LEVEL = 11
22+ APP_COMPRESS_BR_LEVEL = 11
23+
24+ # -------- 缓存配置 --------
25+ # LRU缓存的限制数量,0表示无限制
26+ LRU_CACHE_MAXSIZE = 10000
27+ # LRU缓存不重新分配的容量
28+ LRU_CACHE_CAPACITY = 10000
29+ # TTL缓存的限制数量,0表示无限制
30+ TTL_CACHE_MAXSIZE = 0
31+ # TTL缓存过期时间(秒)
32+ TTL_CACHE_EXPIRE = 600
Original file line number Diff line number Diff line change @@ -23,6 +23,17 @@ class AppSettings(BaseSettings):
2323 app_compress_br_level : int = 11
2424
2525
26+ class CacheSettings (BaseSettings ):
27+ """
28+ 缓存配置
29+ """
30+
31+ lru_cache_maxsize : int = 10000
32+ lru_cache_capacity : int = 10000
33+ ttl_cache_maxsize : int = 0
34+ ttl_cache_expire : int = 600
35+
36+
2637class GetConfig :
2738 """
2839 获取配置
@@ -39,6 +50,14 @@ def get_app_config(self):
3950 # 实例化应用配置模型
4051 return AppSettings ()
4152
53+ @lru_cache ()
54+ def get_cache_config (self ):
55+ """
56+ 获取缓存配置
57+ """
58+ # 实例化缓存配置模型
59+ return CacheSettings ()
60+
4261 @staticmethod
4362 def parse_cli_args ():
4463 """
@@ -66,6 +85,8 @@ def parse_cli_args():
6685get_config = GetConfig ()
6786# 应用配置
6887AppConfig = get_config .get_app_config ()
88+ # 缓存配置
89+ CacheConfig = get_config .get_cache_config ()
6990
7091
7192class ApiConfig :
Original file line number Diff line number Diff line change 11from cachebox import LRUCache , TTLCache
22from flask import session
33from typing import Any , Dict
4+ from config .env import CacheConfig
45
56
6- cache_manager = LRUCache (maxsize = 10000 , iterable = None , capacity = 10000 )
7- ttl_manager = TTLCache (maxsize = 0 , ttl = 600 )
7+ cache_manager = LRUCache (
8+ maxsize = CacheConfig .lru_cache_maxsize ,
9+ iterable = None ,
10+ capacity = CacheConfig .lru_cache_capacity ,
11+ )
12+ ttl_manager = TTLCache (
13+ maxsize = CacheConfig .ttl_cache_maxsize , ttl = CacheConfig .ttl_cache_expire
14+ )
815
916
1017class CacheManager :
You can’t perform that action at this time.
0 commit comments