Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'internal/source/gitlab/cache/entry.go')
-rw-r--r--internal/source/gitlab/cache/entry.go45
1 files changed, 22 insertions, 23 deletions
diff --git a/internal/source/gitlab/cache/entry.go b/internal/source/gitlab/cache/entry.go
index d91bb331..191ef789 100644
--- a/internal/source/gitlab/cache/entry.go
+++ b/internal/source/gitlab/cache/entry.go
@@ -13,23 +13,28 @@ import (
// holds a pointer to *api.Lookup when the domain lookup has been retrieved
// successfully
type Entry struct {
- domain string
- created time.Time
- retrieve *sync.Once
- refresh *sync.Once
- mux *sync.RWMutex
- retrieved chan struct{}
- response *api.Lookup
+ domain string
+ created time.Time
+ retrieve *sync.Once
+ refresh *sync.Once
+ mux *sync.RWMutex
+ retrieved chan struct{}
+ response *api.Lookup
+ refreshTimeout time.Duration
+ retriever *Retriever
}
-func newCacheEntry(domain string) *Entry {
+func newCacheEntry(domain string, refreshTimeout time.Duration, retriever *Retriever) *Entry {
+
return &Entry{
- domain: domain,
- created: time.Now(),
- retrieve: &sync.Once{},
- refresh: &sync.Once{},
- mux: &sync.RWMutex{},
- retrieved: make(chan struct{}),
+ domain: domain,
+ created: time.Now(),
+ retrieve: &sync.Once{},
+ refresh: &sync.Once{},
+ mux: &sync.RWMutex{},
+ retrieved: make(chan struct{}),
+ refreshTimeout: refreshTimeout,
+ retriever: retriever,
}
}
@@ -61,7 +66,7 @@ func (e *Entry) Lookup() *api.Lookup {
// Retrieve perform a blocking retrieval of the cache entry response.
func (e *Entry) Retrieve(ctx context.Context, client api.Client) (lookup *api.Lookup) {
- e.retrieve.Do(func() { go e.retrieveWithClient(client) })
+ e.retrieve.Do(func() { go e.setResponse(e.retriever.Retrieve(e.domain)) })
select {
case <-ctx.Done():
@@ -77,7 +82,7 @@ func (e *Entry) Retrieve(ctx context.Context, client api.Client) (lookup *api.Lo
func (e *Entry) Refresh(client api.Client, store Store) {
e.refresh.Do(func() {
go func() {
- entry := newCacheEntry(e.domain)
+ entry := newCacheEntry(e.domain, e.refreshTimeout, e.retriever)
entry.Retrieve(context.Background(), client)
@@ -86,12 +91,6 @@ func (e *Entry) Refresh(client api.Client, store Store) {
})
}
-func (e *Entry) retrieveWithClient(client api.Client) {
- retriever := Retriever{client: client}
-
- e.setResponse(retriever.Retrieve(e.domain))
-}
-
func (e *Entry) setResponse(lookup api.Lookup) {
e.mux.Lock()
defer e.mux.Unlock()
@@ -101,7 +100,7 @@ func (e *Entry) setResponse(lookup api.Lookup) {
}
func (e *Entry) isExpired() bool {
- return time.Since(e.created) > shortCacheExpiry
+ return time.Since(e.created) > e.refreshTimeout
}
func (e *Entry) isResolved() bool {