diff options
Diffstat (limited to 'internal/vfs/zip/vfs.go')
-rw-r--r-- | internal/vfs/zip/vfs.go | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/internal/vfs/zip/vfs.go b/internal/vfs/zip/vfs.go index d90d4796..b27424c6 100644 --- a/internal/vfs/zip/vfs.go +++ b/internal/vfs/zip/vfs.go @@ -56,12 +56,7 @@ func New(cfg *config.ZipServing) vfs.VFS { openTimeout: cfg.OpenTimeout, } - zipVFS.cache = cache.New(zipVFS.cacheExpirationInterval, zipVFS.cacheCleanupInterval) - zipVFS.cache.OnEvicted(func(s string, i interface{}) { - metrics.ZipCachedEntries.WithLabelValues("archive").Dec() - - i.(*zipArchive).onEvicted() - }) + zipVFS.resetCache() // TODO: To be removed with https://gitlab.com/gitlab-org/gitlab-pages/-/issues/480 zipVFS.dataOffsetCache = newLruCache("data-offset", defaultDataOffsetItems, defaultDataOffsetExpirationInterval) @@ -70,6 +65,31 @@ func New(cfg *config.ZipServing) vfs.VFS { return zipVFS } +// Reconfigure will update the zipVFS configuration values and will reset the +// cache +func (fs *zipVFS) Reconfigure(cfg *config.Config) error { + fs.cacheLock.Lock() + defer fs.cacheLock.Unlock() + + fs.openTimeout = cfg.Zip.OpenTimeout + fs.cacheExpirationInterval = cfg.Zip.ExpirationInterval + fs.cacheRefreshInterval = cfg.Zip.RefreshInterval + fs.cacheCleanupInterval = cfg.Zip.CleanupInterval + + fs.resetCache() + + return nil +} + +func (fs *zipVFS) resetCache() { + fs.cache = cache.New(fs.cacheExpirationInterval, fs.cacheCleanupInterval) + fs.cache.OnEvicted(func(s string, i interface{}) { + metrics.ZipCachedEntries.WithLabelValues("archive").Dec() + + i.(*zipArchive).onEvicted() + }) +} + func (fs *zipVFS) keyFromPath(path string) (string, error) { // We assume that our URL is https://.../artifacts.zip?content-sign=aaa // our caching key is `https://.../artifacts.zip` |