From 6fe0880e115701b06e76e8f16ae6ba6deb8a2fcc Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Mon, 3 Mar 2025 16:06:56 +0100 Subject: [PATCH] feat(ffi): add a method to clear all the non-critical caches of a client --- bindings/matrix-sdk-ffi/src/client.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/bindings/matrix-sdk-ffi/src/client.rs b/bindings/matrix-sdk-ffi/src/client.rs index b8886dd4b..2301b1595 100644 --- a/bindings/matrix-sdk-ffi/src/client.rs +++ b/bindings/matrix-sdk-ffi/src/client.rs @@ -18,6 +18,7 @@ use matrix_sdk::{ }, OidcAuthorizationData, OidcSession, }, + event_cache::EventCacheError, media::{ MediaFileHandle as SdkMediaFileHandle, MediaFormat, MediaRequestParameters, MediaThumbnailSettings, @@ -1159,6 +1160,28 @@ impl Client { let alias = RoomAliasId::parse(alias)?; self.inner.is_room_alias_available(&alias).await.map_err(Into::into) } + + /// Clear all the non-critical caches for this Client instance. + /// + /// - This will empty all the room's persisted event caches, so all rooms + /// will start as if they were empty. + /// - This will empty the media cache according to the current media + /// retention policy. + pub async fn clear_caches(&self) -> Result<(), ClientError> { + let closure = async || -> Result<_, EventCacheError> { + let store = self.inner.event_cache_store().lock().await?; + + // Clear all the room chunks. + store.clear_all_rooms_chunks().await?; + + // Clean up the media cache according to the current media retention policy. + store.clean_up_media_cache().await?; + + Ok(()) + }; + + Ok(closure().await?) + } } #[matrix_sdk_ffi_macros::export(callback_interface)]