在程序的某些部分中显式禁用MySQL查询缓存 [英] Explicit disable MySQL query cache in some parts of program

查看:74
本文介绍了在程序的某些部分中显式禁用MySQL查询缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Django项目中,某些cronjob程序主要用于管理或分析目的,例如生成网站使用情况统计信息,轮换用户活动日志等.

In a Django project, some cronjob programs are mainly used for administrative or analysis purposes, e.g. generating site usage stats, rotating user activities log, etc.

我们可能不希望MySQL在那些程序中缓存查询以节省内存使用并提高查询缓存效率.

We probably do not hope MySQL to cache queries in those programs to save memory usage and improve query cache efficiency.

是否有可能在那些程序中显式关闭MySQL查询缓存,同时为其他所有部分(包括所有 views.py )启用它?

Is it possible to turn off MySQL query cache explicitly in those programs while keep it enabled for other parts including all views.py?

推荐答案

http://dev.mysql.com/doc/refman/5.1/en/query-cache-configuration.html

单个客户端可以通过设置SESSION query_cache_type值来控制其自己的连接的缓存行为.例如,客户端可以禁止对自己的查询使用查询缓存,如下所示:

Individual clients can control cache behavior for their own connection by setting the SESSION query_cache_type value. For example, a client can disable use of the query cache for its own queries like this:

mysql>SET SESSION query_cache_type = OFF;

mysql> SET SESSION query_cache_type = OFF;

不过,通常没有令人信服的理由打扰.查询缓存并不像您想象的那么重要,特别是在非高峰时段(我认为这是您将运行cron作业的时间).

There's not usually a compelling reason to bother, though. The query cache isn't nearly as important as you might think, particularly during off-peak periods (which I assume is when you would run the cron jobs).

这篇关于在程序的某些部分中显式禁用MySQL查询缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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