Helpers to use cachetools with asyncio.
asyncache is available from PyPI and can be installed by running:
pip install asyncache
from asyncache import cached
from cachetools import TTLCache
pool = ...
@cached(TTLCache(1024, 60))
async def get_username(user_id):
rec = await pool.fetchrow(
"""
SELECT
username
FROM
users
WHERE
id = $1
""",
user_id,
)
return rec and rec["username"]
This project is licensed under the MIT License - see the LICENSE file for details.