请求之间共享的类静态属性值 [英] Class static attribute value shared between requests
本文介绍了请求之间共享的类静态属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个静态类属性,该属性在同一个http请求中进行了修改.
I have a a static class attribute that gets modified in the same http request.
class A:
x = {}
def fun(k,v):
A.x[k] = v
我的问题是,当您执行另一个http请求时,前一个请求的最后一个值仍然存在.
My issue is that when your do another http request, the last value of the previous request persists.
我是通过Apache的WSGI模式使用Django的.
Am using Django through Apache's mod WSGI .
如何使静态值持久存在于同一请求中,而不是持久存在于另一个请求中?
How can I make the static value persists in the same request but not to another request?
推荐答案
受泥泞鱼的答案启发,我实现了中间件的process_response
Inspired by muddyfish's answer I implemented a middleware's process_response
import A
class ClearStaticMiddleware(object):
def process_response(self, request, response):
A.x = {}
return response
谢谢大家的答复.
这篇关于请求之间共享的类静态属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文