![](/img/trans.png)
[英]Django / WSGI - How to profile partial request? My profiling tools are per-request but app runs out of memory before then
[英]How to implement per-request in-memory “cache” of value in django
我想在数据库中存储一个值,该值在请求/响应周期中不会发生变化,但会被使用数百次(可能是数千次)。
例如:
#somefile.py
def get_current_foo(request): # this gets called a lot and is currently a bottleneck
foo = get_foo_from_db(request.blah)
return foo
目前我使用memcached来存储值,但是这个东西被调用得足够多,即使使用memcached来存储值也是一个瓶颈(我在说话时对它进行分析)。 有没有办法在当前请求/响应周期中“缓存”内存中的值?
(跟进来自Are python“全局”(模块)变量线程本地吗? )
如果是每请求数据,则将其存储在请求对象本身上。 :-)
请参阅Django中的按请求缓存? 对于某些技术这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.