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)
| 158 | /// This method should only be called during init or upgrade hooks to ensure that the cache is |
| 159 | /// up-to-date with the repository and that we have enough instructions to rebuild the cache. |
| 160 | pub fn build_cache(&self) { |
| 161 | if self.len() > Self::MAX_CACHE_SIZE { |
| 162 | print(format!( |
| 163 | "Only the first {} user groups will be added to the cache, the reposity has {} user groups.", |
| 164 | Self::MAX_CACHE_SIZE, |
| 165 | self.len(), |
| 166 | )); |
| 167 | } |
| 168 | |
| 169 | CACHE.with(|cache| { |
| 170 | cache.borrow_mut().clear(); |
| 171 | |
| 172 | DB.with(|db| { |
| 173 | for (_, user_group) in db.borrow().iter().take(Self::MAX_CACHE_SIZE) { |
| 174 | cache.borrow_mut().insert(user_group.id, user_group); |
| 175 | } |
| 176 | }); |
| 177 | }); |
| 178 | } |
| 179 | |
| 180 | pub fn find_by_name(&self, name: &str) -> Option<UserGroup> { |
| 181 | self.unique_index |