Exemple #1
2
def get_hero(area=0):
    cache_key = CACHE_PREFIX+":cached_sets:get_hero:"+str(area)
    hero = cache.get(cache_key)
    if hero is None:
        log.cache_miss(cache_key)
        try:
            hero = Featured.objects.filter(area=area)[0].flowgram
        except IndexError:
            hero = None
        cache.add(cache_key, hero, EXPIRATION)
    else:
        log.cache_hit(cache_key)
    return hero
Exemple #2
2
def get_featured(area):
    cache_key = CACHE_PREFIX+":cached_sets:get_featured:" + str(area)
    flowgrams = cache.get(cache_key)
    if flowgrams is None:
        log.cache_miss(cache_key)
        featured = Featured.objects.filter(area=area)[1:100]
        flowgrams = []
        for rank, features in itertools.groupby(featured, lambda x: x.rank):
            l = [feat.flowgram for feat in features]
            random.shuffle(l)
            flowgrams.extend(l)
        cache.set(cache_key, flowgrams, EXPIRATION)
    else:
        log.cache_hit(cache_key)
    return flowgrams