From fd5d19dab16e46debf4aab4002ab003f4799e890 Mon Sep 17 00:00:00 2001 From: KurimuzonAkuma Date: Thu, 7 Mar 2024 12:39:50 +0300 Subject: [PATCH] Allow to specify a limit to message cache size --- pyrogram/client.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index c6e2117b..47685e4e 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -190,6 +190,10 @@ class Client(Methods): A value that is too high may result in network related issues. Defaults to 1. + max_message_cache_size (``int``, *optional*): + Set the maximum size of the message cache. + Defaults to 10000. + storage_engine (:obj:`~pyrogram.storage.Storage`, *optional*): Pass an instance of your own implementation of session storage engine. Useful when you want to store your session in databases like Mongo, Redis, etc. @@ -217,6 +221,7 @@ class Client(Methods): UPDATES_WATCHDOG_INTERVAL = 15 * 60 MAX_CONCURRENT_TRANSMISSIONS = 1 + MAX_MESSAGE_CACHE_SIZE = 10000 mimetypes = MimeTypes() mimetypes.readfp(StringIO(mime_types)) @@ -251,6 +256,7 @@ class Client(Methods): sleep_threshold: int = Session.SLEEP_THRESHOLD, hide_password: bool = False, max_concurrent_transmissions: int = MAX_CONCURRENT_TRANSMISSIONS, + max_message_cache_size: int = MAX_MESSAGE_CACHE_SIZE, storage_engine: Storage = None, init_connection_params: "raw.base.JSONValue" = None ): @@ -284,6 +290,7 @@ class Client(Methods): self.sleep_threshold = sleep_threshold self.hide_password = hide_password self.max_concurrent_transmissions = max_concurrent_transmissions + self.max_message_cache_size = max_message_cache_size self.init_connection_params = init_connection_params self.executor = ThreadPoolExecutor(self.workers, thread_name_prefix="Handler") @@ -320,7 +327,7 @@ class Client(Methods): self.me: Optional[User] = None - self.message_cache = Cache(10000) + self.message_cache = Cache(self.max_message_cache_size) # Sometimes, for some reason, the server will stop sending updates and will only respond to pings. # This watchdog will invoke updates.GetState in order to wake up the server and enable it sending updates again