@@ -51,9 +51,33 @@ def load_translations(self) -> None:
5151
5252
5353class Bot (bridge .Bot ):
54- def __init__ (self , * args : Any , ** options : Any ) -> None :
54+ def __init__ (
55+ self , * args : Any , cache_type : str = "memory" , cache_config : dict [str , Any ] | None = None , ** options : Any
56+ ) -> None :
5557 self .translations : list [ExtensionTranslation ] = options .pop ("translations" , [])
56- self .cache : aiocache .SimpleMemoryCache | aiocache .RedisCache = aiocache .SimpleMemoryCache ()
58+
59+ self .botkit_cache : aiocache .BaseCache
60+ # Initialize cache based on type and config
61+ if cache_type == "redis" :
62+ if cache_config :
63+ logger .info ("Using Redis cache" )
64+ self .botkit_cache = aiocache .RedisCache (
65+ endpoint = cache_config .get ("host" , "localhost" ),
66+ port = cache_config .get ("port" , 6379 ),
67+ db = cache_config .get ("db" , 0 ),
68+ password = cache_config .get ("password" ),
69+ ssl = cache_config .get ("ssl" , False ),
70+ namespace = "botkit" ,
71+ )
72+ else :
73+ logger .warning (
74+ "Redis cache type specified but no configuration provided. Falling back to memory cache."
75+ )
76+ self .botkit_cache = aiocache .SimpleMemoryCache (namespace = "botkit" )
77+ else :
78+ logger .info ("Using memory cache" )
79+ self .botkit_cache = aiocache .SimpleMemoryCache (namespace = "botkit" )
80+
5781 super ().__init__ (* args , ** options )
5882
5983 @self .listen (name = "on_ready" , once = True )
0 commit comments