Пример #1
0
def get_all_questions():
    """
        Retrieve all question from DB and save to HashMap
        note: this will take a while to load but the web call response will be between 1-5 millisec.
    """
    questions = ObjectMemoryCache.get_key(Question)
    if questions is None:
        questions = Question.objects
        ''' set in cache '''
        memo = ObjectMemoryCache(Question, "qid")
        memo.queryset(questions)
        memo.load(serialize=True, serializer_class=QuestionResponse)
        ''' get key '''
        questions = ObjectMemoryCache.get_key(Question)
    return questions
Пример #2
0
 def get(self, request, limit=20):
     token = TokenMiddleware.get_token(request)
     if token is None:
         raise NotAuthenticated("Token invalid or expired!")
     uid = str(token.get(PARAMETER_UID))
     
     leader_table = ObjectMemoryCache.get_key(Leaderboard)
     if leader_table:
         leader_table = leader_table.values()
     else:
         ''' retrieve X leaders from leaderboard table '''
         leader_table = Leaderboard.objects[:limit]
         if len(leader_table) == 0:
             return []
         memo = ObjectMemoryCache(Leaderboard, PARAMETER_ID)
         memo.queryset(leader_table)
         memo.load(serialize=True, serializer_class=Leader)
         leader_table = memo.get_key(Leaderboard)
     return Response(leader_table)
Пример #3
0
 def get(self, request):
     categories = ObjectMemoryCache.get_key(Category)
     if categories:
         categories = categories.values()
     else:
         ''' extract all categories with status 'active' true '''
         categories = Category.objects(active=True)
         if len(categories) == 0:
             return Response([])
         ''' put categories in memory '''
         memo = ObjectMemoryCache(Category, PARAMETER_CATEGORY_ID)
         memo.queryset(categories)
         loaded, categories = memo.load(serialize=True, serializer_class=CategoryResponse)
         if not loaded:
             raise APIException(detail="Unable to load categories")            
     return Response(categories)