I am currently using Django and memcached to keep track of a Zip object like so:
activeList_data = cache.get(active_list_key)
if not activeList_data:
activeTickers, activeName = get_most_active()
activeList = zip(activeTickers, activeName)
cache.set(1, activeList, cache_time)
However, whenever I try to print the cache it just returns a blank list. Any ideas on where I am going wrong? Thanks
EDIT: For reference here is my full code
activeList_data = cache.get(active_list_key) # returns None if no key-value pair
if not activeList_data:
activeTickers, activeName = get_most_active()
print(activeTickers)
if not activeTickers:
# If blank list returned (weekends) then use
# previous data stored in models
tickerList = []
nameList = []
most_active = MostActiveStock.objects.all()
for ticker in most_active.ticker:
tickerList.append(ticker)
for name in most_active.name:
nameList.append(name)
activeList = zip(activeTickers, activeName)
print(1)
else:
activeTickers = activeTickers[:3]
activeName = activeName[:3]
activeList = zip(activeTickers, activeName)
print(list(activeList))
# Delete all old data
MostActiveStock.objects.all().delete()
# Store latest data for IEX's weekend blackouts
for ticker, name in activeList:
most_active_obj = MostActiveStock.objects.create(ticker=ticker, name=name)
print(2)
cache.set(active_list_key, activeList, cache_time)
print(3)
else:
activeList = activeList_data
print(4)
print(list(activeList))
context_dict['activeList'] = activeList