cache clean implemented

This commit is contained in:
2026-05-29 03:46:47 -06:00
parent a9de607743
commit 248c1370d7
9 changed files with 48 additions and 17 deletions
+9 -2
View File
@@ -13,7 +13,10 @@ import (
"time"
)
const userAgent = "pacman/7.1.0 (Linux x86_64) libalpm/16.0.1"
const (
userAgent = "pacman/7.1.0 (Linux x86_64) libalpm/16.0.1"
repoArch = "os/x86_64"
)
type Cache struct {
cfg CacheConfig
@@ -30,6 +33,8 @@ type CacheConfig struct {
DialTimeout time.Duration
ResponseHeaderTimeout time.Duration
ClientTimeout time.Duration
MaxCacheSize int64
MaxCacheAge time.Duration
}
type inFlight struct {
@@ -46,13 +51,15 @@ type CacheFile struct {
Filename string
}
func NewCache(cacheRoot string, mirrorURLs []string, mirroredRepos []string) (*Cache, error) {
func NewCache(cacheRoot string, mirrorURLs []string, mirroredRepos []string, maxCacheSize int64, maxCacheAge time.Duration) (*Cache, error) {
cfg := CacheConfig{
mirrorURLs: mirrorURLs,
mirroredRepos: mirroredRepos,
DialTimeout: 5 * time.Second,
ResponseHeaderTimeout: 10 * time.Second,
ClientTimeout: 0 * time.Second,
MaxCacheSize: maxCacheSize,
MaxCacheAge: maxCacheAge,
}
transport := &http.Transport{
+3 -1
View File
@@ -30,7 +30,9 @@ func newTestCache(t *testing.T, mirrorURLs []string) *Cache {
// set slog to debug
slog.SetLogLoggerLevel(slog.LevelDebug)
mirroredRepos := []string{"core", "extra"}
c, err := NewCache(t.TempDir(), mirrorURLs, mirroredRepos)
maxSize := int64(1024)
maxAge := time.Duration(10 * time.Second)
c, err := NewCache(t.TempDir(), mirrorURLs, mirroredRepos, maxSize, maxAge)
if err != nil {
t.Fatalf("failed to create cache: %v", err)
}