from itertools import count import pytest import faust from faust.web import Blueprint, View DEFAULT_TIMEOUT = 361.363 VIEW_B_TIMEOUT = 64.3 blueprint = Blueprint('test') cache = blueprint.cache(timeout=DEFAULT_TIMEOUT) class ResponseModel(faust.Record): key: str value: int @blueprint.route('/A/', name='a') class ACachedView(View): def __post_init__(self) -> None: self.counter = count() @cache.view() async def get(self, request): return await self._next_response(request) async def _next_response(self, request): cache_key = cache.key_for_request(request, None, request.method) return self.json( ResponseModel(
import aredis import pytest from mode.utils.mocks import Mock import faust from faust.exceptions import ImproperlyConfigured from faust.web import Blueprint, View from faust.web.cache import backends from faust.web.cache.backends import redis DEFAULT_TIMEOUT = 361.363 VIEW_B_TIMEOUT = 64.3 blueprint = Blueprint("test") cache = blueprint.cache(timeout=None) class ResponseModel(faust.Record): key: str value: int @blueprint.route("/A/", name="a") class ACachedView(View): def __post_init__(self) -> None: self.counter = count() @cache.view(timeout=DEFAULT_TIMEOUT) async def get(self, request): return await self._next_response(request)