示例#1
0
 def load_tweets_through_cache(cls, user_id):
     # Django query is lazy loading
     # it is triggered by iterations inside the load_object()
     queryset = Tweet.objects.filter(
         user_id=user_id).order_by('-created_at')
     name = USER_TWEET_PATTERN.format(user_id=user_id)
     return RedisHelper.load_objects(name, queryset)
示例#2
0
 def get_cached_newsfeeds(cls, user_id):
     key = USER_NEWSFEEDS_PATTERN.format(user_id=user_id)
     if GateKeeper.is_switch_on('switch_newsfeed_to_hbase'):
         serializer = HBaseModelSerializer
     else:
         serializer = DjangoModelSerializer
     return RedisHelper.load_objects(key,
                                     lazy_load_newsfeeds(user_id),
                                     serializer=serializer)
示例#3
0
 def get_cached_tweet(cls, user_id):
     # queryset is lazy loading, here is not get data from db yet
     queryset = Tweet.objects.filter(
         user_id=user_id).order_by('-created_at')
     key = USER_TWEETS_PATTERN.format(user_id=user_id)
     return RedisHelper.load_objects(key, queryset)
 def get_cached_newsfeeds(cls, user_id):
     queryset = NewsFeed.objects.filter(user_id=user_id).order_by('-created_at')
     key = USER_NEWSFEEDS_PATTERN.format(user_id=user_id)
     return RedisHelper.load_objects(key, queryset)
示例#5
0
 def get_cached_tweets(cls, user_id):
     queryset = Tweet.objects.filter(
         user_id=user_id).order_by('-created_at')
     key = USER_TWEETS_PATTERN.format(user_id=user_id)
     return RedisHelper.load_objects(key, queryset)
示例#6
0
 def get_cached_tweets(cls, user_id):
     key = USER_TWEETS_PATTERN.format(user_id=user_id)
     return RedisHelper.load_objects(key, lazy_load_tweets(user_id))
示例#7
0
 def load_newsfeeds_through_cache(cls, user_id):
     # queryset lazy loading
     queryset = NewsFeed.objects.filter(user_id=user_id)
     name = USER_NEWSFEED_PATTERN.format(user_id=user_id)
     return RedisHelper.load_objects(name, queryset)
示例#8
0
 def get_cached_tweets(cls, user_id):
     # Queryset is lazy loading
     # 此时并没有进行数据库的访问,只有需要进行iteration的时候才会真正查询数据库
     queryset = Tweet.objects.filter(user_id=user_id).order_by('-created_at')
     key = USER_TWEETS_PATTERN.format(user_id=user_id)
     return RedisHelper.load_objects(key, queryset)
示例#9
0
 def get_cached_tweets(cls, user_id):
     # queryset is lazy loading, it will loaded when it's needed. eg, for loop queryset, list(queryset)
     queryset = Tweet.objects.filter(
         user_id=user_id).order_by('-created_at')
     key = USER_TWEETS_PATTERN.format(user_id=user_id)
     return RedisHelper.load_objects(key, queryset)
示例#10
0
 def get_cached_tweets(cls, user_id):
     # Queryset is lazy loading, this statement doesn't incur real database query
     queryset = Tweet.objects.filter(
         user_id=user_id).order_by('-created_at')
     key = USER_TWEETS_PATTERN.format(user_id=user_id)
     return RedisHelper.load_objects(key, queryset)