feat:Use distcache

This commit is contained in:
shaohuzhang1 2025-04-17 17:16:45 +08:00
parent 9108971fdc
commit 934871f5c6
4 changed files with 10 additions and 25 deletions

View File

@ -13,13 +13,13 @@ class Cache_Version(Enum):
# 令牌
TOKEN = "TOKEN", lambda token: token
# 工作空间列表
WORKSPACE_LIST = "WORKSPACE::LIST", lambda user_id: user_id
WORKSPACE_LIST = "WORKSPACE:LIST", lambda user_id: user_id
# 用户数据
USER = "USER", lambda user_id: user_id
# 当前用户所有的角色
ROLE_LIST = "ROLE::LIST", lambda user_id: user_id
ROLE_LIST = "ROLE:LIST", lambda user_id: user_id
# 当前用户所有权限
PERMISSION_LIST = "PERMISSION::LIST", lambda user_id: user_id
PERMISSION_LIST = "PERMISSION:LIST", lambda user_id: user_id
def get_version(self):
return self.value[0]

View File

@ -29,16 +29,6 @@ class Config(dict):
# 语言
'LANGUAGE_CODE': 'zh-CN',
"DEBUG": False,
# redis 目前先支持单机 哨兵的配置后期加上
'REDIS_HOST': '127.0.0.1',
# 端口
'REDIS_PORT': 6379,
# 密码
'REDIS_PASSWORD': 'Password123@postgres',
# 库
'REDIS_DB': 0,
# 最大连接数
'REDIS_MAX_CONNECTIONS': 100
}
def get_debug(self) -> bool:
@ -61,17 +51,12 @@ class Config(dict):
}
}
def get_cache_setting(self):
@staticmethod
def get_cache_setting():
return {
'default': {
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': f'redis://{self.get("REDIS_HOST")}:{self.get("REDIS_PORT")}',
'OPTIONS': {
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
"DB": self.get("REDIS_DB"),
"PASSWORD": self.get("REDIS_PASSWORD"),
"CONNECTION_POOL_KWARGS": {"max_connections": self.get("REDIS_MAX_CONNECTIONS")}
},
'BACKEND': 'diskcache.DjangoCache',
'LOCATION': f'{PROJECT_DIR}/data/cache'
},
}

View File

@ -13,7 +13,7 @@ from rest_framework.views import APIView
from common.auth.authenticate import TokenAuth
from common.auth.authentication import has_permissions
from common.constants.permission_constants import PermissionConstants
from common.constants.permission_constants import PermissionConstants, Permission, Group, Operate
from common.result import result
from users.api.user import UserProfileAPI, TestWorkspacePermissionUserApi
from users.serializers.user import UserProfileSerializer

View File

@ -11,10 +11,10 @@ django = "5.2"
drf-spectacular = { extras = ["sidecar"], version = "0.28.0" }
django-redis = "5.4.0"
django-db-connection-pool = "1.2.5"
psycopg = {extras = ["binary"], version = "3.2.6"}
psycopg = { extras = ["binary"], version = "3.2.6" }
python-dotenv = "1.1.0"
uuid-utils = "0.10.0"
diskcache = "5.6.3"
diskcache2 = "0.1.2"
[build-system]
requires = ["poetry-core"]