use ic_cdk::storage::stable::StableBTreeMap;
static STORE: StableBTreeMap<String, String> = StableBTreeMap::new();
#[ic_cdk::update]
fn update_and_get(key: String, new_value: String) -> String {
// Update the value
STORE.insert(key.clone(), new_value);
// Retrieve and return the updated value
STORE.get(&key).unwrap_or_else(|| "Not found".to_string())
}
When I insert a data and update via update_and_get some how the STORE.get return the old value instead of lastest update data. After few seconds it will update correctly
I don’t understand the connection of your linked code with the snippet above. If your linked code behaves as described, then I would first suspect some ordering issue with asynchronous requests. Can you rule that out?
If you truly have a write and subsequent read in the same message, as in the snippet, I would be very surprised to see the described behaviour. Can you actually reproduce the issue in a minimal example with the code from the snippet?