WSGI ( is caching mysql result until script code is modified ) code included. ( want to stop this caching )

孤街醉人 提交于 2019-12-02 16:44:46

问题


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 ?

回答1:


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.



来源:https://stackoverflow.com/questions/23046231/wsgi-is-caching-mysql-result-until-script-code-is-modified-code-included

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!