diff --git a/aiocache/decorators.py b/aiocache/decorators.py index 202a45cc9..8ee65fc17 100644 --- a/aiocache/decorators.py +++ b/aiocache/decorators.py @@ -3,12 +3,15 @@ import inspect import logging +import aiojobs + from aiocache.base import SENTINEL from aiocache.factory import Cache, caches from aiocache.lock import RedLock logger = logging.getLogger(__name__) +scheduler = asyncio.run(aiojobs.create_scheduler(pending_limit=0, limit=None)) class cached: @@ -112,9 +115,7 @@ async def decorator( if aiocache_wait_for_write: await self.set_in_cache(key, result) else: - # TODO: Use aiojobs to avoid warnings. - asyncio.create_task(self.set_in_cache(key, result)) - + await scheduler.spawn(self.set_in_cache(key, result)) return result def get_cache_key(self, f, args, kwargs): @@ -336,8 +337,7 @@ async def decorator( if aiocache_wait_for_write: await self.set_in_cache(result, f, args, kwargs) else: - # TODO: Use aiojobs to avoid warnings. - asyncio.create_task(self.set_in_cache(result, f, args, kwargs)) + await scheduler.spawn(self.set_in_cache(result, f, args, kwargs)) return result diff --git a/requirements-dev.txt b/requirements-dev.txt index 591677bf6..73bc49f17 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,4 +1,5 @@ -e .[dev,redis,memcached,msgpack] +aiojobs==1.0.0 aiohttp==3.8.1 flake8==4.0.1 flake8-bandit==3.0.0 diff --git a/setup.py b/setup.py index 889e54342..4a940ab1a 100644 --- a/setup.py +++ b/setup.py @@ -38,6 +38,7 @@ 'redis:python_version>="3.8"': ["aioredis>=1.3.0,<2.0"], "memcached": ["aiomcache>=0.5.2"], "msgpack": ["msgpack>=0.5.5"], + "aiojobs": ["aiojobs>=1.0.0"], }, include_package_data=True, )