MCPcopy Create free account
hub / github.com/dfinity/orbit / build_cache

Method build_cache

core/station/impl/src/repositories/user.rs:208–226  ·  view source on GitHub ↗

Builds the cache from the stable memory repository. This method should only be called during init or upgrade hooks to ensure that the cache is up-to-date with the repository and that we have enough instructions to rebuild the cache.

(&self)

Source from the content-addressed store, hash-verified

206 /// This method should only be called during init or upgrade hooks to ensure that the cache is
207 /// up-to-date with the repository and that we have enough instructions to rebuild the cache.
208 pub fn build_cache(&self) {
209 if self.len() > Self::MAX_CACHE_SIZE {
210 print(format!(
211 "Only the first {} users will be added to the cache, the reposity has {} users.",
212 Self::MAX_CACHE_SIZE,
213 USER_REPOSITORY.len(),
214 ));
215 }
216
217 CACHE.with(|cache| {
218 cache.borrow_mut().clear();
219
220 DB.with(|db| {
221 for (_, user) in db.borrow().iter().take(Self::MAX_CACHE_SIZE) {
222 cache.borrow_mut().insert(user.id, user);
223 }
224 });
225 });
226 }
227
228 /// Returns the user associated with the given identity if it exists.
229 pub fn find_by_identity(&self, identity: &Principal) -> Option<User> {

Callers 1

init_cacheMethod · 0.45

Calls 5

printFunction · 0.85
iterMethod · 0.80
lenMethod · 0.45
clearMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected