我在 Django 3.2 上运行我的网站。我在Django 的缓存框架MemcachedCache
中读到该框架已python-memcached
被弃用。我安装pymemcache==3.5.0
在我的登台服务器上并更改为CACHE_URL=pymemcache://127.0.0.1:11211
in env.ini
。但是,如果我使用 pip 卸载python-memcached
,我会收到一条错误消息,表明MemcachedCache
我的代码仍在使用它,并且它在import memcache
.
我的代码使用以下导入:
from django.core.cache import cache
from django.core.cache.backends.base import DEFAULT_TIMEOUT
我该如何替换MemcachedCache
,PyMemcacheCache
以便MemcachedCache
不会在我的代码中使用?
我正在使用django-environ==0.8.1
并CACHES
在我的设置中定义:
CACHES = {
'default': env.cache()
}
env
定义为environ.Env()
。
我的回溯:
Environment:
Request Method: GET
Request URL: https://<...>
Django Version: 3.2.10
Python Version: 3.8.12
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'crispy_forms',
'friendship',
'rules.apps.AutodiscoverRulesConfig',
'sorl.thumbnail',
'speedy.core.base',
'speedy.core.accounts',
'speedy.core.blocks',
'speedy.core.uploads',
'speedy.core.messages',
'speedy.core.profiles',
'speedy.core.friends',
'speedy.core.about',
'speedy.core.privacy',
'speedy.core.terms',
'speedy.net.accounts',
'speedy.match.accounts',
'speedy.match.likes',
'speedy.composer.accounts',
'speedy.mail.accounts',
'speedy.core.contact_by_form',
'speedy.match.profiles',
'speedy.match.matches']
Installed Middleware:
['speedy.core.base.middleware.SessionCookieDomainMiddleware',
'speedy.core.base.middleware.RemoveExtraSlashesMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.contrib.sites.middleware.CurrentSiteMiddleware',
'django.middleware.locale.LocaleMiddleware',
'speedy.core.base.middleware.LocaleDomainMiddleware',
'speedy.core.base.middleware.EnsureCachesMiddleware',
'speedy.core.base.middleware.UpdateSessionAuthHashMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'speedy.core.accounts.middleware.SiteProfileMiddleware']
Traceback (most recent call last):
File "<...>/env/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "<...>/./speedy/core/base/middleware.py", line 139, in __call__
block_managers.ensure_caches(user=request.user)
File "<...>/./speedy/core/blocks/managers.py", line 46, in ensure_caches
blocked_entities = cache_manager.cache_get(blocked_key, sliding_timeout=DEFAULT_TIMEOUT)
File "<...>/./speedy/core/base/cache_manager.py", line 21, in cache_get
wrapped_value = cache.get(key, default=DEFAULT_VALUE, version=version)
File "<...>/env/lib/python3.8/site-packages/django/utils/connection.py", line 15, in __getattr__
return getattr(self._connections[self._alias], item)
File "<...>/env/lib/python3.8/site-packages/django/utils/connection.py", line 62, in __getitem__
conn = self.create_connection(alias)
File "<...>/env/lib/python3.8/site-packages/django/core/cache/__init__.py", line 44, in create_connection
return backend_cls(location, params)
File "<...>/env/lib/python3.8/site-packages/django/core/cache/backends/memcached.py", line 181, in __init__
import memcache
Exception Type: ModuleNotFoundError at /matches/
Exception Value: No module named 'memcache'
我的存储库:https ://github.com/speedy-net/speedy-net
更新:我检查了我收到的用于调试的电子邮件,我看到CACHES
in 设置等于{'default': {'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', 'LOCATION': '127.0.0.1:11211'}}
.
我在https://github.com/joke2k/django-environ/issues/359上提交了一个问题(可能是一个错误)