Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ coverage.txt
.DS_Store
/webp_server_go
/metadata/*
/.idea/inspectionProfiles/Project_Default.xml
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var (
PrefetchForeground bool // Standalone prefetch, prefetch and exit
AllowNonImage bool
Config = NewWebPConfig()
Version = "0.13.6"
Version = "0.13.7"
WriteLock = cache.New(5*time.Minute, 10*time.Minute)
ConvertLock = cache.New(5*time.Minute, 10*time.Minute)
LocalHostAlias = "local"
Expand Down
24 changes: 24 additions & 0 deletions schedule/cache_clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,27 @@ func CleanCache() {
}
}
}

func DeleteDeadCache() {
ticker := time.NewTicker(30 * time.Second)
defer ticker.Stop()
threshold := time.Now().Add(-10 * time.Minute)
for {
select {
case <-ticker.C:
_ = filepath.Walk(os.TempDir()+"vips-", func(path string, info os.FileInfo, err error) error {
log.Debugf("Checking possible dead cache: %s", path)
if err != nil {
return err
}
if info.IsDir() && info.ModTime().Before(threshold) {
// only delete directory
log.Warnf("Deleting: %s", path)
_ = os.RemoveAll(path)
return filepath.SkipDir
}
return nil
})
}
}
}
1 change: 1 addition & 0 deletions webp-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func init() {
}

func main() {
go schedule.DeleteDeadCache()
if config.Config.MaxCacheSize != 0 {
go schedule.CleanCache()
}
Expand Down