Skip to content

Commit 934871f

Browse files
committed
feat:Use distcache
1 parent 9108971 commit 934871f

File tree

4 files changed

+10
-25
lines changed

4 files changed

+10
-25
lines changed

apps/common/constants/cache_version.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ class Cache_Version(Enum):
1313
# 令牌
1414
TOKEN = "TOKEN", lambda token: token
1515
# 工作空间列表
16-
WORKSPACE_LIST = "WORKSPACE::LIST", lambda user_id: user_id
16+
WORKSPACE_LIST = "WORKSPACE:LIST", lambda user_id: user_id
1717
# 用户数据
1818
USER = "USER", lambda user_id: user_id
1919
# 当前用户所有的角色
20-
ROLE_LIST = "ROLE::LIST", lambda user_id: user_id
20+
ROLE_LIST = "ROLE:LIST", lambda user_id: user_id
2121
# 当前用户所有权限
22-
PERMISSION_LIST = "PERMISSION::LIST", lambda user_id: user_id
22+
PERMISSION_LIST = "PERMISSION:LIST", lambda user_id: user_id
2323

2424
def get_version(self):
2525
return self.value[0]

apps/maxkb/conf.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,6 @@ class Config(dict):
2929
# 语言
3030
'LANGUAGE_CODE': 'zh-CN',
3131
"DEBUG": False,
32-
# redis 目前先支持单机 哨兵的配置后期加上
33-
'REDIS_HOST': '127.0.0.1',
34-
# 端口
35-
'REDIS_PORT': 6379,
36-
# 密码
37-
'REDIS_PASSWORD': 'Password123@postgres',
38-
# 库
39-
'REDIS_DB': 0,
40-
# 最大连接数
41-
'REDIS_MAX_CONNECTIONS': 100
4232
}
4333

4434
def get_debug(self) -> bool:
@@ -61,17 +51,12 @@ def get_db_setting(self) -> dict:
6151
}
6252
}
6353

64-
def get_cache_setting(self):
54+
@staticmethod
55+
def get_cache_setting():
6556
return {
6657
'default': {
67-
'BACKEND': 'django_redis.cache.RedisCache',
68-
'LOCATION': f'redis://{self.get("REDIS_HOST")}:{self.get("REDIS_PORT")}',
69-
'OPTIONS': {
70-
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
71-
"DB": self.get("REDIS_DB"),
72-
"PASSWORD": self.get("REDIS_PASSWORD"),
73-
"CONNECTION_POOL_KWARGS": {"max_connections": self.get("REDIS_MAX_CONNECTIONS")}
74-
},
58+
'BACKEND': 'diskcache.DjangoCache',
59+
'LOCATION': f'{PROJECT_DIR}/data/cache'
7560
},
7661
}
7762

apps/users/views/user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from common.auth.authenticate import TokenAuth
1515
from common.auth.authentication import has_permissions
16-
from common.constants.permission_constants import PermissionConstants
16+
from common.constants.permission_constants import PermissionConstants, Permission, Group, Operate
1717
from common.result import result
1818
from users.api.user import UserProfileAPI, TestWorkspacePermissionUserApi
1919
from users.serializers.user import UserProfileSerializer

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ django = "5.2"
1111
drf-spectacular = { extras = ["sidecar"], version = "0.28.0" }
1212
django-redis = "5.4.0"
1313
django-db-connection-pool = "1.2.5"
14-
psycopg = {extras = ["binary"], version = "3.2.6"}
14+
psycopg = { extras = ["binary"], version = "3.2.6" }
1515
python-dotenv = "1.1.0"
1616
uuid-utils = "0.10.0"
17-
diskcache = "5.6.3"
17+
diskcache2 = "0.1.2"
1818

1919
[build-system]
2020
requires = ["poetry-core"]

0 commit comments

Comments
 (0)