Allow to specify a limit to message cache size

Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
KurimuzonAkuma 2024-03-07 12:39:50 +03:00 committed by wulan17
parent c394a3ea3a
commit 8584ea3599
No known key found for this signature in database
GPG key ID: 318CD6CD3A6AC0A5

View file

@ -203,6 +203,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.
client_platform (:obj:`~pyrogram.enums.ClientPlatform`, *optional*):
The platform where this client is running.
Defaults to 'other'
@ -224,6 +228,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))
@ -259,7 +264,8 @@ class Client(Methods):
sleep_threshold: int = Session.SLEEP_THRESHOLD,
hide_password: Optional[bool] = False,
max_concurrent_transmissions: int = MAX_CONCURRENT_TRANSMISSIONS,
client_platform: "enums.ClientPlatform" = enums.ClientPlatform.OTHER
client_platform: "enums.ClientPlatform" = enums.ClientPlatform.OTHER,
max_message_cache_size: int = MAX_MESSAGE_CACHE_SIZE
):
super().__init__()
@ -292,6 +298,7 @@ class Client(Methods):
self.hide_password = hide_password
self.max_concurrent_transmissions = max_concurrent_transmissions
self.client_platform = client_platform
self.max_message_cache_size = max_message_cache_size
self.executor = ThreadPoolExecutor(self.workers, thread_name_prefix="Handler")
@ -341,7 +348,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