Hi this is doing my head in. Sometimes functions I have in python (django) return a number and sometimes a nonetype (irrespective of cache period). It prints the cache in the method but the function still seems to return nonetype. Often the cache will not show in a print function but also do not run the method as if it were actually ‘None’
#get total user L3 hours worked def totalUserL3hours(user1): user_L3_hrs = cache.get('user_L3_hrs'+user1.username) print("User l3 cache hours are {}".format(user_L3_hrs)) if user_L3_hrs is None: a=0.0 l3_total = user1.L3s.all() for l3 in l3_total: x = l3.indivMachineHoursWorked() a=a+x cache.set('user_L3_hrs'+user1.username, a, 1800) print("User l3 hours are {}".format(a)) return user_L3_hrs def TotUserL3Mined(user1): # a = 0.0 # l3_total = request.user.L3s.all() x = totalUserL3hours(user1) b = btcToHourL3() print("xxxxxxxxxxxxxxxxxx is :".format(x)) c = x*b return c
with:
User l3 cache hours are 504.41816050055553
xxxxxxxxxxxxxxxxxx is :
Local Variables:
b
1.992805616092481e-05
x
None
Settings:
CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.db.DatabaseCache', 'LOCATION': 'my_cache_table', } }