Пример #1
0
def getBagInstance(userID, lensID, update = False):
	cacheKey = userBagCacheKey(userID, lensID)
	bagInstance = memcache.get(cacheKey)
	if bagInstance is None or update:
		bagInstance = userLensBag.all().filter('userID = ', userID).filter('lensID = ', lensID).get()
		memcache.set(cacheKey, bagInstance)
	return bagInstance
Пример #2
0
def getAllUses(update=False):
	#get all uses from all lenses
	currentUses = memcache.get('allLensUses')
	if currentUses is None or update:
		allInstances = userLensBag.all()
		currentUses = parseUsesFromBag(allInstances)
		memcache.set('allLensUses', currentUses)
	return currentUses
Пример #3
0
def getLensUses(lensID, update = False):
	#get only uses associated with this lensID
	thisLensUses =  memcache.get('lensUsesFor' + lensID)
	if thisLensUses is None or update:
		allInstances = userLensBag.all().filter('lensID =', lensID)
		thisLensUses = parseUsesFromBag(allInstances)
		memcache.set('lensUsesFor' + lensID,thisLensUses)
	return thisLensUses
Пример #4
0
def getLensStats(lensID, update = False):
	cacheKey = 'currentLensStats' + lensID
	currentStats = memcache.get(cacheKey)
	if currentStats is None or update == True:
		allInstances = userLensBag.all().filter('lensID =', lensID)
		currentStats = makeStatCalculation(allInstances)
		memcache.set(cacheKey, currentStats)
	return currentStats
Пример #5
0
def updateUserBag(userID, fetch = False):
	userBag = userLensBag.all().filter('userID = ', userID)
	cachedBag = []
	for lens in userBag:
		cachedBag.append(lens)		
	cacheKey = userBagCacheKey(userID)
	memcache.set(cacheKey, cachedBag)
	if fetch:
		return cachedBag
Пример #6
0
def getTotalLensInstances(refresh = False):
	totalInstances = memcache.get('totalLensInstances')
	if totalInstances is None or refresh:
		totalInstances = 0
		allBagObjects = userLensBag.all()
		listAllBags = []
		for bagObject in allBagObjects:
			listAllBags.append(bagObject.userID)		
		for userID in getAllUsers():
			if userID in listAllBags:
				totalInstances += 1
		memcache.set('totalLensInstances', totalInstances)
	return totalInstances