Write will serialize on disk the entity cache file
()
| 152 | |
| 153 | // Write will serialize on disk the entity cache file |
| 154 | func (sc *SubCache[EntityT, ExcerptT, CacheT]) write() error { |
| 155 | sc.mu.RLock() |
| 156 | defer sc.mu.RUnlock() |
| 157 | |
| 158 | var data bytes.Buffer |
| 159 | |
| 160 | aux := struct { |
| 161 | Version uint |
| 162 | Excerpts map[entity.Id]ExcerptT |
| 163 | }{ |
| 164 | Version: sc.version, |
| 165 | Excerpts: sc.excerpts, |
| 166 | } |
| 167 | |
| 168 | encoder := gob.NewEncoder(&data) |
| 169 | |
| 170 | err := encoder.Encode(aux) |
| 171 | if err != nil { |
| 172 | return err |
| 173 | } |
| 174 | |
| 175 | f, err := sc.repo.LocalStorage().Create(filepath.Join("cache", sc.namespace)) |
| 176 | if err != nil { |
| 177 | return err |
| 178 | } |
| 179 | |
| 180 | _, err = f.Write(data.Bytes()) |
| 181 | if err != nil { |
| 182 | _ = f.Close() |
| 183 | return err |
| 184 | } |
| 185 | |
| 186 | return f.Close() |
| 187 | } |
| 188 | |
| 189 | func (sc *SubCache[EntityT, ExcerptT, CacheT]) Build() <-chan BuildEvent { |
| 190 | // value chosen experimentally as giving the fasted indexing, while |
no test coverage detected