Resolve retrieve an entity matching the exact given id
(id entity.Id)
| 350 | |
| 351 | // Resolve retrieve an entity matching the exact given id |
| 352 | func (sc *SubCache[EntityT, ExcerptT, CacheT]) Resolve(id entity.Id) (CacheT, error) { |
| 353 | sc.mu.RLock() |
| 354 | cached, ok := sc.cached[id] |
| 355 | if ok { |
| 356 | sc.lru.Get(id) |
| 357 | sc.mu.RUnlock() |
| 358 | return cached, nil |
| 359 | } |
| 360 | sc.mu.RUnlock() |
| 361 | |
| 362 | e, err := sc.actions.ReadWithResolver(sc.repo, sc.resolvers(), id) |
| 363 | if err != nil { |
| 364 | return *new(CacheT), err |
| 365 | } |
| 366 | |
| 367 | cached = sc.makeCached(e, sc.entityUpdated) |
| 368 | |
| 369 | sc.mu.Lock() |
| 370 | sc.cached[id] = cached |
| 371 | sc.lru.Add(id) |
| 372 | sc.mu.Unlock() |
| 373 | |
| 374 | sc.evictIfNeeded() |
| 375 | |
| 376 | return cached, nil |
| 377 | } |
| 378 | |
| 379 | // ResolvePrefix retrieve an entity matching an id prefix. It fails if multiple |
| 380 | // entities match. |
no test coverage detected