I've got a simple function to get some additional data based on request.user:
def getIsland(request):
try:
island = Island.objects.get(user=request.user) # Retrieve
except Island.DoesNotExist:
island = Island(user=request.user) # Doesn't exist, create default one
island.save()
island.update() # Run scheduled tasks
return island # Return
The problem is that the function gets called in many different places (middleware, templates, views ETC) and thus executes the query many times. Any way to help that? ie
def getIsland(request):
if HasBeenEvaluatedAlreadyOnThisRequest: return cached
else:
[...]