Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFI Bindings: Expose CryptoStore clear caches #3462

Merged
merged 5 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions bindings/matrix-sdk-crypto-ffi/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test this? It doesn't crash? Don't you need to modify the export line at the top of the impl block to #[uniffi::export(async_runtime = "tokio")] for it not to crash?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I have tried, and no crash

self.inner.clear_crypto_cache().await
}
}

impl OlmMachine {
Expand Down
4 changes: 4 additions & 0 deletions crates/matrix-sdk-crypto/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,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))

Expand Down
7 changes: 7 additions & 0 deletions crates/matrix-sdk-crypto/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading