I'd like to store a value from the database that isn't going to change during a request/response cycle, but gets used hundreds (potentially thousands) of times.
e.g.:
#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
Currently I use memcached to store the value, but this thing gets called enough that even using memcached to store the value is a bottleneck (I'm profiling it as we speak). Is there a way to "cache" the value in-memory for the current request/response cycle?
( follow up from Are python "global" (module) variables thread local? )