在Django应用程序中执行memcached需要执行哪些步骤? [英] What steps are needed to implement memcached in a Django application?

查看:177
本文介绍了在Django应用程序中执行memcached需要执行哪些步骤?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我现有的Django Web应用程序,使用MySQLDB而不用memcaching。
我想实现memcaching来提高这个网站的响应能力。我看到这里的说明。



但是,这些说明给我留下了一些未回答的问题。在安装memcached服务器之后,我需要做的是让memcache工作吗?或者我需要更改我的任何代码在settings.py之外?当模型被读取或写入时,Django是否可以很好地处理幕后的所有memcaching操作? (如果是这样,这很酷!)我如何看到memcaching对DB访问数量有什么改进?

解决方案

你所做的只是一个缓存后端的设置。



为了从缓存中获益,你需要找到适合的地方,对性能的积极影响:您的视图模板 ..您可以缓存整个视图,模板,模板片段等。



如果您想要一些自动化来帮助您,请查看 Johnny Cache 包:


Johnny Cache是​​django应用程序的缓存框架。它使用
与django缓存抽象,但是专门开发了使用memcache的
。它的主要功能是
Django的ORM的补丁,它会以一致的
方式自动缓存所有读取。


django-cache-machine package:


Cache Machine通过ORM为Django
模型提供自动缓存和无效。


还有一个有趣的项目叫做 django-cacheops 旨在改进Django ORM缓存,但它使用 Redis 后端。



另外, django_debug_toolbar 的缓存面板可以帮助您。



请注意,django查询器有一个内置的内部缓存,但它与缓存框架无关。



进一步阅读:




I have my existing Django web application that uses a MySQLDB without memcaching. I would like to implement memcaching to improve the responsiveness of this site. I see the instructions here.

However, these instructions leave me with some unanswered question(s). Is this all I need to do to get memcache working after I setup the memcached server? Or do I need to alter any of my code outside of settings.py? Does Django nicely handle all the memcaching operations behind the scenes for me whenever models are read or written? (If so, that's very cool!) How can I see what improvement the memcaching is having on the number of DB accesses?

解决方案

What you've done is just a set up of a Cache Backend.

In order to benefit from caching you need to find the places where it is appropriate and would have a positive impact on performance: your views, templates..you can cache the whole views, templates, template fragments etc.

If you want some automation to help you, take a look at Johnny Cache package:

Johnny Cache is a caching framework for django applications. It works with the django caching abstraction, but was developed specifically with the use of memcached in mind. Its main feature is a patch on Django’s ORM that automatically caches all reads in a consistent manner.

Or django-cache-machine package:

Cache Machine provides automatic caching and invalidation for Django models through the ORM.

There is also an interesting project called django-cacheops that is aiming to improve Django ORM caching, but it uses Redis backend.

Also, django_debug_toolbars caching panel can help you in the future.

Note that django querysets have a built-in internal cache, but it has nothing to do with a cache framework.

Further reading:

这篇关于在Django应用程序中执行memcached需要执行哪些步骤?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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