如何在 django 项目中使用 memcached? [英] How to use memcached in django project?

查看:63
本文介绍了如何在 django 项目中使用 memcached?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 django-project,我想减少数据库请求开销.所以我正在尝试使用 django-cache(需要 Memcached)

I am working on django-project ,I want to reduce database request overhead. So I am trying with django-cache (Requires Memcached)

vi /etc/sysconfig/memcached

PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64" We increased memory size up to 256
OPTIONS="" added IP address "-l 127.0.0.1" 

在项目中更改设置如下:在settings.py中添加了新变量

Changes settings as follows in project:Added new variable in settings.py

CACHE_BACKEND='memcached://localhost:11211'
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'

[注意:重启memcached:/etc/init.d/memcached restart]

[ Note : restart memcached: /etc/init.d/memcached restart]

项目正在运行,它减少了数据库请求开销:但这带来了某些问题:几次后我失去了我的会话.所以我需要在应用程序中再次登录,我该如何处理,我只想存储会话详细信息.

Project is working, It reduces the database request overhead: but that brings certain issues: I lost my session after few time. So I need to login again in application,how can I handle this,I want to store only session details.

推荐答案

您正在正确使用它,但请记住,如果您重新启动 memcached,您将失去所有现有会话.这在意料之中.

You are using it correctly but keep in mind that if you restart memcached, you will loose all your existing sessions. That's to be expected.

这篇关于如何在 django 项目中使用 memcached?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆