mirror of
https://github.com/stashapp/stash.git
synced 2026-03-29 00:22:30 +01:00
Merge cec75c9445 into fd480c5a3e
This commit is contained in:
commit
c748722000
2 changed files with 28 additions and 12 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package pkg
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
@ -10,22 +11,23 @@ type cacheEntry struct {
|
|||
}
|
||||
|
||||
type repositoryCache struct {
|
||||
mu sync.RWMutex
|
||||
// cache maps the URL to the last modified time and the data
|
||||
cache map[string]cacheEntry
|
||||
}
|
||||
|
||||
func (c *repositoryCache) ensureCache() {
|
||||
if c.cache == nil {
|
||||
c.cache = make(map[string]cacheEntry)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *repositoryCache) lastModified(url string) *time.Time {
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
c.ensureCache()
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
|
||||
if c.cache == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
e, found := c.cache[url]
|
||||
|
||||
if !found {
|
||||
|
|
@ -36,7 +38,13 @@ func (c *repositoryCache) lastModified(url string) *time.Time {
|
|||
}
|
||||
|
||||
func (c *repositoryCache) getPackageList(url string) []RemotePackage {
|
||||
c.ensureCache()
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
|
||||
if c.cache == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
e, found := c.cache[url]
|
||||
|
||||
if !found {
|
||||
|
|
@ -51,7 +59,13 @@ func (c *repositoryCache) cacheList(url string, lastModified time.Time, data []R
|
|||
return
|
||||
}
|
||||
|
||||
c.ensureCache()
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
if c.cache == nil {
|
||||
c.cache = make(map[string]cacheEntry)
|
||||
}
|
||||
|
||||
c.cache[url] = cacheEntry{
|
||||
lastModified: lastModified,
|
||||
data: data,
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
|
|
@ -31,13 +32,14 @@ type Manager struct {
|
|||
|
||||
Client *http.Client
|
||||
|
||||
cache *repositoryCache
|
||||
cacheOnce sync.Once
|
||||
cache *repositoryCache
|
||||
}
|
||||
|
||||
func (m *Manager) getCache() *repositoryCache {
|
||||
if m.cache == nil {
|
||||
m.cacheOnce.Do(func() {
|
||||
m.cache = &repositoryCache{}
|
||||
}
|
||||
})
|
||||
|
||||
return m.cache
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue