|
3 | 3 | import inspect |
4 | 4 | import logging |
5 | 5 |
|
| 6 | +import aiojobs |
| 7 | + |
6 | 8 | from aiocache.base import SENTINEL |
7 | 9 | from aiocache.factory import Cache, caches |
8 | 10 | from aiocache.lock import RedLock |
9 | 11 |
|
10 | 12 |
|
11 | 13 | logger = logging.getLogger(__name__) |
| 14 | +loop = asyncio.get_event_loop() |
| 15 | +scheduler = loop.run_until_complete(aiojobs.create_scheduler(pending_limit=0, limit=None)) |
12 | 16 |
|
13 | 17 |
|
14 | 18 | class cached: |
@@ -112,9 +116,7 @@ async def decorator( |
112 | 116 | if aiocache_wait_for_write: |
113 | 117 | await self.set_in_cache(key, result) |
114 | 118 | else: |
115 | | - # TODO: Use aiojobs to avoid warnings. |
116 | | - asyncio.create_task(self.set_in_cache(key, result)) |
117 | | - |
| 119 | + await scheduler.spawn(self.set_in_cache(key, result)) |
118 | 120 | return result |
119 | 121 |
|
120 | 122 | def get_cache_key(self, f, args, kwargs): |
@@ -336,8 +338,7 @@ async def decorator( |
336 | 338 | if aiocache_wait_for_write: |
337 | 339 | await self.set_in_cache(result, f, args, kwargs) |
338 | 340 | else: |
339 | | - # TODO: Use aiojobs to avoid warnings. |
340 | | - asyncio.create_task(self.set_in_cache(result, f, args, kwargs)) |
| 341 | + await scheduler.spawn(self.set_in_cache(result, f, args, kwargs)) |
341 | 342 |
|
342 | 343 | return result |
343 | 344 |
|
|
0 commit comments