Caching.
This commit is contained in:
		
							parent
							
								
									c1eeacc0b4
								
							
						
					
					
						commit
						21ab5628b0
					
				
							
								
								
									
										17
									
								
								src/snek/system/cache.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								src/snek/system/cache.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,17 @@ | |||||||
|  | 
 | ||||||
|  | import functools  | ||||||
|  | 
 | ||||||
|  | cache = functools.cache | ||||||
|  | 
 | ||||||
|  | def async_cache(func): | ||||||
|  |     cache = {} | ||||||
|  | 
 | ||||||
|  |     @functools.wraps(func) | ||||||
|  |     async def wrapper(*args): | ||||||
|  |         if args in cache: | ||||||
|  |             return cache[args] | ||||||
|  |         result = await func(*args) | ||||||
|  |         cache[args] = result | ||||||
|  |         return result | ||||||
|  | 
 | ||||||
|  |     return wrapper | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user