Always cache files smaller than 10MB, now in the database

This removes the need for a .clear_cache() method as now files
are identified by their MD5 (which needs to be calculated
always) and their file size (to make collisions even more
unlikely) instead using the file path (which can now change).
This commit is contained in:
Lonami Exo
2018-01-05 15:33:25 +01:00
parent a489b4b18b
commit c4e26c95f5
3 changed files with 76 additions and 41 deletions

View File

@@ -759,13 +759,8 @@ class TelegramClient(TelegramBareClient):
for ext in ('.png', '.jpg', '.gif', '.jpeg')
)
file_hash = hash(file)
if file_hash in self._upload_cache:
file_handle = self._upload_cache[file_hash]
else:
self._upload_cache[file_hash] = file_handle = self.upload_file(
file, progress_callback=progress_callback
)
file_handle = self.upload_file(
file, progress_callback=progress_callback)
if as_photo and not force_document:
media = InputMediaUploadedPhoto(file_handle, caption)
@@ -835,14 +830,6 @@ class TelegramClient(TelegramBareClient):
reply_to=reply_to,
is_voice_note=()) # empty tuple is enough
def clear_file_cache(self):
"""Calls to .send_file() will cache the remote location of the
uploaded files so that subsequent files can be immediate, so
uploading the same file path will result in using the cached
version. To avoid this a call to this method should be made.
"""
self._upload_cache.clear()
# endregion
# region Downloading media requests