Example #1
0
 def decorated(*args, **kwargs):
     key = key_pattern % args
     sent = cache.get(key)
     if sent:
         return True
     cache.set(key, 1, timeout=300)
     return f(*args, **kwargs)
Example #2
0
def flag_topic(tid):
    key = 'flag:%d:t-%d' % (current_user.id, tid)
    if cache.get(key):
        return '', 204
    cache.inc(key)
    TopicStat(tid).flag()
    return '', 204
Example #3
0
 def validate_title(self, field):
     data = u'%s%s' % (field.data, self.content.data)
     key = hashlib.md5(to_bytes(data)).hexdigest()
     if cache.get(key):
         raise StopValidation("Duplicate requesting")
     # avoid duplicate requesting
     cache.set(key, 1, 100)
Example #4
0
 def validate_title(self, field):
     data = u'%s%s' % (field.data, self.content.data)
     key = hashlib.md5(to_bytes(data)).hexdigest()
     if cache.get(key):
         raise StopValidation("Duplicate requesting")
     # avoid duplicate requesting
     cache.set(key, 1, 100)
Example #5
0
def flag_topic(tid):
    key = 'flag:%d:t-%d' % (current_user.id, tid)
    if cache.get(key):
        return '', 204
    cache.inc(key)
    TopicStat(tid).flag()
    return '', 204
Example #6
0
 def decorated(*args, **kwargs):
     key = key_pattern % args
     sent = cache.get(key)
     if sent:
         return True
     cache.set(key, 1, timeout=300)
     return f(*args, **kwargs)
Example #7
0
def hook_for_render():
    use_app = session.get('app')

    if not is_robot() and use_app == 'yes':
        return render_template('front/app.html')

    key = 'front:page:%s' % request.path
    content = cache.get(key)
    if content:
        return render_content(content)
Example #8
0
def hook_for_render():
    use_app = session.get('app')

    if not is_robot() and use_app == 'yes':
        return render_template('front/app.html')

    key = 'front:page:%s' % request.path
    content = cache.get(key)
    if content:
        return render_content(content)
Example #9
0
        def decorated(*args, **kwargs):
            if current_user or request.method != 'GET':
                return f(*args, **kwargs)

            key = 'api:%s' % request.full_path
            response = cache.get(key)
            if response:
                return response
            response = f(*args, **kwargs)
            cache.set(key, response, cache_time)
            return response
Example #10
0
def flag_topic_comment(tid, cid):
    key = 'flag:%d:c-%d' % (current_user.id, cid)
    if cache.get(key):
        return '', 204
    comment = get_comment_or_404(tid, cid)
    # here is a concurrency bug, but it doesn't matter
    comment.flag_count += 1
    with db.auto_commit():
        db.session.add(comment)
    # one person, one flag
    cache.inc(key)
    return '', 204
Example #11
0
def flag_topic_comment(tid, cid):
    key = 'flag:%d:c-%d' % (current_user.id, cid)
    if cache.get(key):
        return '', 204
    comment = get_comment_or_404(tid, cid)
    # here is a concurrency bug, but it doesn't matter
    comment.flag_count += 1
    with db.auto_commit():
        db.session.add(comment)
    # one person, one flag
    cache.inc(key)
    return '', 204
Example #12
0
    def filter_count(self, **kwargs):
        mapper = self._only_mapper_zero()
        model = mapper.class_
        if not kwargs:
            key = model.generate_cache_prefix('count')
            rv = cache.get(key)
            if rv is not None:
                return rv
            q = self.select_from(model).with_entities(func.count(1))
            rv = q.scalar()
            cache.set(key, rv, CACHE_TIMES['count'])
            return rv

        prefix = model.generate_cache_prefix('fc')
        key = prefix + '-'.join(['%s$%s' % (k, kwargs[k]) for k in kwargs])
        rv = cache.get(key)
        if rv:
            return rv
        q = self.select_from(model).with_entities(func.count(1))
        rv = q.filter_by(**kwargs).scalar()
        cache.set(key, rv, CACHE_TIMES['fc'])
        return rv
Example #13
0
 def filter_first(self, **kwargs):
     mapper = self._only_mapper_zero()
     prefix = mapper.class_.generate_cache_prefix('ff')
     key = prefix + '-'.join(['%s$%s' % (k, kwargs[k]) for k in kwargs])
     rv = cache.get(key)
     if rv:
         return rv
     rv = self.filter_by(**kwargs).first()
     if rv is None:
         return None
     # it is hard to invalidate this cache, expires in 2 minutes
     cache.set(key, rv, CACHE_TIMES['ff'])
     return rv
Example #14
0
    def get(self, ident):
        mapper = self._only_full_mapper_zero('get')

        if isinstance(ident, (list, tuple)):
            suffix = '-'.join(map(str, ident))
        else:
            suffix = str(ident)

        key = mapper.class_.generate_cache_prefix('get') + suffix
        rv = cache.get(key)
        if rv:
            return rv
        rv = super(CacheQuery, self).get(ident)
        if rv is None:
            return None
        cache.set(key, rv, CACHE_TIMES['get'])
        return rv
Example #15
0
 def validate_content(self, field):
     key = hashlib.md5(to_bytes(field.data)).hexdigest()
     if cache.get(key):
         raise StopValidation("Duplicate requesting")
     # avoid duplicate requesting
     cache.set(key, 1, 100)
Example #16
0
 def validate_content(self, field):
     key = hashlib.md5(to_bytes(field.data)).hexdigest()
     if cache.get(key):
         raise StopValidation("Duplicate requesting")
     # avoid duplicate requesting
     cache.set(key, 1, 100)
Example #17
0
def hook_for_render():
    key = 'feed:xml:%s' % request.path
    xml = cache.get(key)
    if xml:
        return Response(xml, content_type='text/xml; charset=UTF-8')
Example #18
0
def hook_for_render():
    key = 'feed:xml:%s' % request.path
    xml = cache.get(key)
    if xml:
        return Response(xml, content_type='text/xml; charset=UTF-8')