(f func(ExcerptT) bool)
| 422 | } |
| 423 | |
| 424 | func (sc *SubCache[EntityT, ExcerptT, CacheT]) resolveMatcher(f func(ExcerptT) bool) (entity.Id, error) { |
| 425 | sc.mu.RLock() |
| 426 | defer sc.mu.RUnlock() |
| 427 | |
| 428 | // preallocate but empty |
| 429 | matching := make([]entity.Id, 0, 5) |
| 430 | |
| 431 | for _, excerpt := range sc.excerpts { |
| 432 | if f(excerpt) { |
| 433 | matching = append(matching, excerpt.Id()) |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | if len(matching) > 1 { |
| 438 | return entity.UnsetId, entity.NewErrMultipleMatch(sc.typename, matching) |
| 439 | } |
| 440 | |
| 441 | if len(matching) == 0 { |
| 442 | return entity.UnsetId, entity.NewErrNotFound(sc.typename) |
| 443 | } |
| 444 | |
| 445 | return matching[0], nil |
| 446 | } |
| 447 | |
| 448 | func (sc *SubCache[EntityT, ExcerptT, CacheT]) add(e EntityT) (CacheT, error) { |
| 449 | sc.mu.Lock() |
no test coverage detected