Canister memory on stable var not persisting

I’m testing testing my app locally. I finally got my JS front end and my motoko backend to where I’m not getting any error messages when I make canister calls. But I’m not quite getting the result I’m expecting just yet. I have a stable variable and a canister call to make updates to said stable variable, but it appears that the updates aren’t being saved within the canister’s memory. No error messages and I’m actually getting an ok. status return. I’m writing to ask, is there any additional settings/configurations that I should be aware of when testing out the persisted memory state of a canister locally? the object I mean to retrieve from the motoko canister is a Trie. Do i need to convert this to an array first before sending it to me front end?

It will be easier to help if you share your code.

My mistake. I meant to attach the links. I’ve attached the links for the two relevant actors below. The goal is to dynamically create a new canister of the actor class type Page. I want for each principal to have their own canister. The role of the main.mo file is essentially to route each user to their particular canister using the user’s principal to retrieve data from the Page actor that belongs to the user making the call.

`https://github.com/JessAYrn/SampleCode/blob/main/src/dtc/main.mo

Ok, thanks. And which function calls do not persist which data?

The updatePageEntry() method within the main.mo file calls the createEntry() method that’s in the Page actor. The createEntry() method then saves the user’s data within private stable var page : Trie.Trie<Nat, PageEntry> = Trie.empty();.

I can confirm that it is being saved. I suspect there’s something wrong with the way I’m dynamically creating the actors.

Likely. Everytime you invoke

                let page = await Page.Page(callerId); 

you are creating a new canister with the code from Page – not sure if that’s what you want

That actually sounds pretty plausible. and that’s not the intended result. How would I get it to where it’s creating a single canister for each principal and the same canister is used when I invokeawait Page.Page(callerId);. i want a single canister to correspond to each principal.

You maintain a map from principal to cabister reference. If the caller has an entry in that map, use it. If not, create a new canister and add it to the map.

Thank you. I’ll give it another try.
Do you have a simple example that you could link?

No, unfortunately not. …

The example below sounds similar, but instead of an array of buckets indexed by key you would use a map indexed by caller principal.

Working sample

1 Like

I got it working Thanks to y’all. Much appreciated :pray:t5: