diff --git a/bindings/matrix-sdk-crypto-ffi/src/machine.rs b/bindings/matrix-sdk-crypto-ffi/src/machine.rs index 1cdace317da..c5daafd1a0b 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/machine.rs +++ b/bindings/matrix-sdk-crypto-ffi/src/machine.rs @@ -1534,6 +1534,17 @@ impl OlmMachine { } .into() } + + /// Clear any in-memory caches because they may be out of sync with the + /// underlying data store. + /// + /// The crypto store layer is caching olm sessions for a given device. + /// When used in a multi-process context this cache will get outdated. + /// If the machine is used by another process, the cache must be + /// invalidating when the main process is resumed. + pub async fn clear_crypto_cache(&self) { + self.inner.clear_crypto_cache().await + } } impl OlmMachine { diff --git a/crates/matrix-sdk-crypto/CHANGELOG.md b/crates/matrix-sdk-crypto/CHANGELOG.md index 24d59af2e8b..aa26987f66b 100644 --- a/crates/matrix-sdk-crypto/CHANGELOG.md +++ b/crates/matrix-sdk-crypto/CHANGELOG.md @@ -50,6 +50,10 @@ Deprecations: Additions: + +- Expose new method `OlmMachine::clear_crypto_cache()`, with FFI bindings + ([#3462](https://github.com/matrix-org/matrix-rust-sdk/pull/3462)) + - Expose new method `OlmMachine::upload_device_keys()`. ([#3457](https://github.com/matrix-org/matrix-rust-sdk/pull/3457)) diff --git a/crates/matrix-sdk-crypto/src/machine.rs b/crates/matrix-sdk-crypto/src/machine.rs index 02180c307f7..9fecf91ca6a 100644 --- a/crates/matrix-sdk-crypto/src/machine.rs +++ b/crates/matrix-sdk-crypto/src/machine.rs @@ -2150,6 +2150,13 @@ impl OlmMachine { let account = cache.account().await?; Ok(account.uploaded_key_count()) } + + /// Clear any in-memory caches because they may be out of sync with the + /// underlying data store. + pub async fn clear_crypto_cache(&self) { + let crypto_store = self.store().crypto_store(); + crypto_store.as_ref().clear_caches().await; + } } /// A set of requests to be executed when bootstrapping cross-signing using