NewNamedRepoCache create or open a named cache on top of a raw repository. The caller is expected to read all returned events before the cache is considered ready to use.
(r repository.ClockedRepo, name string)
| 83 | // The caller is expected to read all returned events before the cache is considered |
| 84 | // ready to use. |
| 85 | func NewNamedRepoCache(r repository.ClockedRepo, name string) (*RepoCache, chan BuildEvent) { |
| 86 | c := &RepoCache{ |
| 87 | repo: r, |
| 88 | name: name, |
| 89 | } |
| 90 | |
| 91 | c.identities = NewRepoCacheIdentity(r, c.getResolvers, c.GetUserIdentity) |
| 92 | c.subcaches = append(c.subcaches, c.identities) |
| 93 | |
| 94 | c.bugs = NewRepoCacheBug(r, c.getResolvers, c.GetUserIdentity) |
| 95 | c.subcaches = append(c.subcaches, c.bugs) |
| 96 | |
| 97 | c.resolvers = entity.Resolvers{ |
| 98 | &IdentityCache{}: entity.ResolverFunc[*IdentityCache](c.identities.Resolve), |
| 99 | &IdentityExcerpt{}: entity.ResolverFunc[*IdentityExcerpt](c.identities.ResolveExcerpt), |
| 100 | &BugCache{}: entity.ResolverFunc[*BugCache](c.bugs.Resolve), |
| 101 | &BugExcerpt{}: entity.ResolverFunc[*BugExcerpt](c.bugs.ResolveExcerpt), |
| 102 | } |
| 103 | |
| 104 | // small buffer so that below functions can emit an event without blocking |
| 105 | events := make(chan BuildEvent) |
| 106 | |
| 107 | go func() { |
| 108 | defer close(events) |
| 109 | |
| 110 | err := c.lock(events) |
| 111 | if err != nil { |
| 112 | events <- BuildEvent{Err: err} |
| 113 | return |
| 114 | } |
| 115 | |
| 116 | err = c.load() |
| 117 | if err == nil { |
| 118 | return |
| 119 | } |
| 120 | |
| 121 | // Cache is either missing, broken or outdated. Rebuilding. |
| 122 | c.buildCache(events) |
| 123 | }() |
| 124 | |
| 125 | return c, events |
| 126 | } |
| 127 | |
| 128 | func NewRepoCacheNoEvents(r repository.ClockedRepo) (*RepoCache, error) { |
| 129 | cache, events := NewRepoCache(r) |
no test coverage detected