コード例 #1
0
ファイル: forms.py プロジェクト: 343829084/zerqu
 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)
コード例 #2
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)
コード例 #3
0
ファイル: sendmails.py プロジェクト: 343829084/zerqu
 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)
コード例 #4
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)
コード例 #5
0
ファイル: feeds.py プロジェクト: 343829084/zerqu
def site_feed():
    topics, _ = get_all_topics()
    title = current_app.config.get('SITE_NAME')
    web_url = canonical_url('front.home')
    self_url = canonical_url('.site_feed')
    xml = u''.join(yield_feed(title, web_url, self_url, topics))
    key = 'feed:xml:%s' % request.path
    cache.set(key, xml, ONE_HOUR)
    return Response(xml, content_type='text/xml; charset=UTF-8')
コード例 #6
0
def site_feed():
    topics, _ = get_all_topics()
    title = current_app.config.get('SITE_NAME')
    web_url = canonical_url('front.home')
    self_url = canonical_url('.site_feed')
    xml = u''.join(yield_feed(title, web_url, self_url, topics))
    key = 'feed:xml:%s' % request.path
    cache.set(key, xml, ONE_HOUR)
    return Response(xml, content_type='text/xml; charset=UTF-8')
コード例 #7
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
コード例 #8
0
ファイル: base.py プロジェクト: valley51/zerqu
 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
コード例 #9
0
ファイル: base.py プロジェクト: valley51/zerqu
    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
コード例 #10
0
def cafe_feed(slug):
    """Show one cafe. This handler is designed for SEO."""
    cafe = Cafe.cache.first_or_404(slug=slug)

    q = db.session.query(CafeTopic.topic_id)
    q = q.filter_by(cafe_id=cafe.id, status=CafeTopic.STATUS_PUBLIC)
    q = q.order_by(CafeTopic.updated_at.desc())
    topics = Topic.cache.get_many([i for i, in q.limit(50)])

    site_name = current_app.config.get('SITE_NAME')
    title = u'%s - %s' % (site_name, cafe.name)

    web_url = canonical_url('front.view_cafe', slug=slug)
    self_url = canonical_url('.cafe_feed', slug=slug)

    xml = u''.join(yield_feed(title, web_url, self_url, topics))
    key = 'feed:xml:{}'.format(slug)
    cache.set(key, xml, ONE_HOUR)
    return Response(xml, content_type='text/xml; charset=UTF-8')
コード例 #11
0
ファイル: feeds.py プロジェクト: 343829084/zerqu
def cafe_feed(slug):
    """Show one cafe. This handler is designed for SEO."""
    cafe = Cafe.cache.first_or_404(slug=slug)

    q = db.session.query(CafeTopic.topic_id)
    q = q.filter_by(cafe_id=cafe.id, status=CafeTopic.STATUS_PUBLIC)
    q = q.order_by(CafeTopic.updated_at.desc())
    topics = Topic.cache.get_many([i for i, in q.limit(50)])

    site_name = current_app.config.get('SITE_NAME')
    title = u'%s - %s' % (site_name, cafe.name)

    web_url = canonical_url('front.view_cafe', slug=slug)
    self_url = canonical_url('.cafe_feed', slug=slug)

    xml = u''.join(yield_feed(title, web_url, self_url, topics))
    key = 'feed:xml:{}'.format(slug)
    cache.set(key, xml, ONE_HOUR)
    return Response(xml, content_type='text/xml; charset=UTF-8')
コード例 #12
0
ファイル: base.py プロジェクト: valley51/zerqu
    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
コード例 #13
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)
コード例 #14
0
ファイル: forms.py プロジェクト: 343829084/zerqu
 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)
コード例 #15
0
ファイル: base.py プロジェクト: valley51/zerqu
 def receive_after_update(mapper, conn, target):
     key = _unique_key(target, mapper.primary_key)
     cache.set(key, target, CACHE_TIMES['get'])
コード例 #16
0
ファイル: front.py プロジェクト: VincentRong/zerqu
def render(template, **kwargs):
    key = 'front:page:%s' % request.path
    content = render_template(template, **kwargs)
    cache.set(key, content, timeout=ONE_HOUR)
    return render_content(content)
コード例 #17
0
def render(template, **kwargs):
    key = 'front:page:%s' % request.path
    content = render_template(template, **kwargs)
    cache.set(key, content, timeout=ONE_HOUR)
    return render_content(content)