Fixed aiocache example according to new loop policy
This commit is contained in:
parent
1660041470
commit
758415d326
|
@ -1,6 +1,6 @@
|
||||||
"""
|
"""
|
||||||
Example of caching using aiocache package. To run it you will need a Redis
|
Example of caching using aiocache package. To run it you will need a Redis
|
||||||
instance running in localhost:6379.
|
instance running in localhost:6379. You can also try with SimpleMemoryCache.
|
||||||
|
|
||||||
Running this example you will see that the first call lasts 3 seconds and
|
Running this example you will see that the first call lasts 3 seconds and
|
||||||
the rest are instant because the value is retrieved from the Redis.
|
the rest are instant because the value is retrieved from the Redis.
|
||||||
|
@ -20,8 +20,12 @@ from aiocache.serializers import JsonSerializer
|
||||||
|
|
||||||
app = Sanic(__name__)
|
app = Sanic(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def init_cache(sanic, loop):
|
||||||
aiocache.settings.set_defaults(
|
aiocache.settings.set_defaults(
|
||||||
class_="aiocache.RedisCache"
|
class_="aiocache.RedisCache",
|
||||||
|
# class_="aiocache.SimpleMemoryCache",
|
||||||
|
loop=loop
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,4 +42,4 @@ async def test(request):
|
||||||
return json(await expensive_call())
|
return json(await expensive_call())
|
||||||
|
|
||||||
|
|
||||||
app.run(host="0.0.0.0", port=8000, loop=asyncio.get_event_loop())
|
app.run(host="0.0.0.0", port=8000, before_start=init_cache)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user