def get_user_by_url(r, u): user = User.objects(url=u).first() raise gen.Return(user) user = yield cache.get(r, u) if user: logging.debug('cache hit for {}'.format(u)) raise gen.Return(user) else: logging.debug('cache miss for {}'.format(u)) user = User.objects(url=u).first() cache.send(r, user) raise gen.Return(user)
def save(self, r=None): if r: cache.invalidate(r, self) cache.send(r, self) return super(User, self).save()