Skip to content

Commit

Permalink
新增 default_cache 配置项,删除其他无用配置
Browse files Browse the repository at this point in the history
  • Loading branch information
leeyisoft committed Jan 2, 2020
1 parent d44cec9 commit 59214ec
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 31 deletions.
7 changes: 1 addition & 6 deletions trest/cache/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,12 @@


BACKENDS = {
'memcached': 'memcached',
'localcache': 'localcache',
'dummy': 'dummy',
'redis': 'rediscache'
}

DEFAULT_CACHE_ALIAS = 'default_redis'
DEFAULT_REDIS_ALIAS = 'default_redis'
DEFAULT_MEMCACHED_ALIAS = 'default_memcache'
DEFAULT_DUMMY_ALIAS = 'dummy'

DEFAULT_CACHE_ALIAS = settings.default_cache
if DEFAULT_CACHE_ALIAS not in settings.CACHES:
raise ConfigError("You must define a '%s' cache" % DEFAULT_CACHE_ALIAS)

Expand Down
2 changes: 1 addition & 1 deletion trest/cache/backends/localcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Thread-safe in-memory cache backend.
"""
import time
from trest.utils import RWLock
from trest.utils.object import RWLock
from .base import BaseCache
from .base import DEFAULT_TIMEOUT

Expand Down
37 changes: 13 additions & 24 deletions trest/config/config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

document = """
# f'{ROOT_PATH}/configs/{env}.yaml'
document = """# f'{ROOT_PATH}/configs/{env}.yaml'
# 注意配置解析出来都是字符串,请不要带单引号或者双引号
# 例如 '0.0.0.0' "0.0.0.0" 都会报错
Expand All @@ -25,9 +24,8 @@
valid_code_key : ab1195c6f0084b4f8b007d3aa7628a38
token_key : f30a2331813f46d0adc2bcf26fcbbbf4
INSTALLED_APPS :
- app1
- admin
rabbitmq_config : ''
sentry_url :
Expand All @@ -44,9 +42,6 @@
- 1 # admin uid
- 2 #
# 是否开启国际化
translation : true
PASSWORD_HASHERS :
# 第一个元素为默认加密方式
- 'trest.utils.hasher.PBKDF2PasswordHasher'
Expand All @@ -59,15 +54,6 @@
- 'trest.middleware.AccessLogMiddleware'
- 'trest.middleware.PushToMQMiddleware'
session :
cache_alias : default_redis
name : nkzpg9NKBpKS2iaK
cookie_domain :
cookie_path : /
expires : 86400
secret : fLjUfxqXtfNoIldA0A0J
version : v0.1.0
# sqlalchemy配置,列出部分,可自行根据sqlalchemy文档增加配置项
# 该配置项对所有连接全局共享
sqlalchemy :
Expand All @@ -78,7 +64,7 @@
'sqlalchemy.connect_args' : {
'connect_timeout' : 3
}
'sqlalchemy.echo' : true
'sqlalchemy.echo' : false
'sqlalchemy.max_overflow' : 10
'sqlalchemy.echo_pool' : true
'sqlalchemy.pool_timeout' : 5
Expand All @@ -98,25 +84,29 @@
DRIVER : 'mysql+mysqldb'
UID : root
# 进过AES加密的密码,格式 aes::: + ciphertext
PASSWD : '123456'
PASSWD : 'eb27acWq#16E1'
HOST : '127.0.0.1'
PORT : 3306
PORT : 33061
DATABASE : 'db_py_admin'
QUERY : {'charset' : 'utf8mb4'}
-
ROLE : 'slave'
DRIVER : 'mysql+mysqldb'
UID : root
# 进过AES加密的密码,格式 aes::: + ciphertext
PASSWD : '123456'
PASSWD : 'eb27acWq#16E1'
HOST : '127.0.0.1'
PORT : 3306
PORT : 33062
DATABASE : 'db_py_admin'
QUERY : {'charset' : 'utf8mb4'}
###########
# 缓存配置 #
###########
# default rediscache 其中之一
default_cache: 'default'
CACHES :
'default':
'BACKEND': 'trest.cache.backends.localcache.LocMemCache'
Expand All @@ -125,12 +115,12 @@
'MAX_ENTRIES': 10000
'CULL_FREQUENCY': 3
'default_redis':
'rediscache':
'BACKEND': 'trest.cache.backends.rediscache.RedisCache'
'LOCATION': '127.0.0.1:6379'
'OPTIONS':
'DB': 0
'PASSWORD': ''
'PASSWORD': 'abc123456'
'PARSER_CLASS': 'redis.connection.DefaultParser'
# 定时ping redis连接池,防止被服务端断开连接(s秒)
'PING_INTERVAL': 120
Expand Down Expand Up @@ -222,5 +212,4 @@
smtp_sever :
smtp_port :
auth_code :
"""

0 comments on commit 59214ec

Please sign in to comment.