WSGI(是缓存的MySQL结果,直到脚本code被修改),包括code。 (希望停止这种缓存) [英] WSGI ( is caching mysql result until script code is modified ) code included. ( want to stop this caching )

查看:129
本文介绍了WSGI(是缓存的MySQL结果,直到脚本code被修改),包括code。 (希望停止这种缓存)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是基本的WSGI code。

 进口MySQLdb的
康恩= MySQLdb.connect(主机=localhost的,
                        用户=根,
                        的passwd =,
                        分贝=一个)
光标= conn.cursor()
cursor.execute(SELECT * FROM`01`其中id在(1,2)限2)
行= cursor.fetchall()
cursor.close()
conn.close()测试=行[0] [1]
测试2 =行[1] [1]高清应用(ENVIRON,start_response):
    start_response('200 OK',[('内涵式','text / html的')])
    产量试验

这里的问题是MySQL结果被缓存..它是不是MySQL的缓存它..我怀疑这是这个脚本这样做。

我想一个解决方案,以阻止这种不必要的缓存。

目前以清除缓存的唯一方法似乎是修改脚本code以上..在..只需更新似乎这样的伎俩。

但我不能只更新24/7 ..必须有把这种缓存关闭的方式。

我要补充一个RAND()号到MySQL查询..将是解决这个问题?显然东西是缓存mysql的结果仅仅是因为无论是

  A)MySQL查询是一样的pviously执行的东西$ P $
b)该脚本尚未自从它执行的MySQL查询修改?


解决方案

执行任何模块级一次,当脚本首次运行或进口。您的应用程序函数总是得到相同的结果,这是第一次运行计算的。

由于奥米德在评论中说,你需要把SQL code在一个从应用功能调用的函数。

This is the basic wsgi code.

import MySQLdb
conn = MySQLdb.connect (host = "localhost",
                        user = "root",
                        passwd = "",
                        db = "a")
cursor = conn.cursor ()
cursor.execute ("select * from `01` where id in (1,2) limit 2")
rows = cursor.fetchall()
cursor.close ()
conn.close ()

test = rows[0][1]
test2 = rows[1][1]

def application(environ, start_response):
    start_response('200 OK', [('content-type', 'text/html')])
    yield test

the problem here is the mysql result is being cached.. it is not mysql caching it.. i suspect it is this script doing it.

i would like a solution to stop this unwanted caching.

currently the only way to clear the caching seems to be to modify the script code above.. as in.. simply updating it seems to do the trick..

but i can not just update it 24/7.. there has to be a way to turn this caching off.

should i add a rand() number to the mysql query.. would that solve the problem ? obviously something is caching the mysql results simply because either

a) the mysql query is same as something previously executed
b) the script has not been modified ever since it executed a mysql query ?

解决方案

Anything at module level is executed once, when the script is first run or imported. Your application function always yields the same result, the one that was calculated on first run.

As Omid says in the comments, you need to put the SQL code in a function that is called from the application function.

这篇关于WSGI(是缓存的MySQL结果,直到脚本code被修改),包括code。 (希望停止这种缓存)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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