| 
									
										
										
										
											2021-01-05 11:22:48 +01:00
										 |  |  | # SPDX-License-Identifier: AGPL-3.0-or-later | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import logging | 
					
						
							| 
									
										
										
										
											2022-07-28 13:02:56 +02:00
										 |  |  | import importlib | 
					
						
							| 
									
										
										
										
											2021-01-05 11:22:48 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | logger = logging.getLogger('searx.shared') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-28 13:02:56 +02:00
										 |  |  | __all__ = ['SharedDict', 'schedule'] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-05 11:22:48 +01:00
										 |  |  | try: | 
					
						
							| 
									
										
										
										
											2022-07-28 13:02:56 +02:00
										 |  |  |     uwsgi = importlib.import_module('uwsgi') | 
					
						
							| 
									
										
										
										
											2021-01-05 11:22:48 +01:00
										 |  |  | except: | 
					
						
							|  |  |  |     # no uwsgi | 
					
						
							|  |  |  |     from .shared_simple import SimpleSharedDict as SharedDict, schedule | 
					
						
							| 
									
										
										
										
											2021-12-27 09:26:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-05 11:22:48 +01:00
										 |  |  |     logger.info('Use shared_simple implementation') | 
					
						
							|  |  |  | else: | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         uwsgi.cache_update('dummy', b'dummy') | 
					
						
							|  |  |  |         if uwsgi.cache_get('dummy') != b'dummy': | 
					
						
							|  |  |  |             raise Exception() | 
					
						
							|  |  |  |     except: | 
					
						
							|  |  |  |         # uwsgi.ini configuration problem: disable all scheduling | 
					
						
							| 
									
										
										
										
											2021-12-27 09:26:22 +01:00
										 |  |  |         logger.error( | 
					
						
							|  |  |  |             'uwsgi.ini configuration error, add this line to your uwsgi.ini\n' | 
					
						
							| 
									
										
										
										
											2022-08-07 12:30:18 +02:00
										 |  |  |             'cache2 = name=searxngcache,items=2000,blocks=2000,blocksize=4096,bitmap=1' | 
					
						
							| 
									
										
										
										
											2021-12-27 09:26:22 +01:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-01-05 11:22:48 +01:00
										 |  |  |         from .shared_simple import SimpleSharedDict as SharedDict | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def schedule(delay, func, *args): | 
					
						
							| 
									
										
										
										
											2021-01-13 14:07:39 +01:00
										 |  |  |             return False | 
					
						
							| 
									
										
										
										
											2021-12-27 09:26:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-05 11:22:48 +01:00
										 |  |  |     else: | 
					
						
							|  |  |  |         # uwsgi | 
					
						
							|  |  |  |         from .shared_uwsgi import UwsgiCacheSharedDict as SharedDict, schedule | 
					
						
							| 
									
										
										
										
											2021-12-27 09:26:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-05 11:22:48 +01:00
										 |  |  |         logger.info('Use shared_uwsgi implementation') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | storage = SharedDict() |