From 25c6a959b53bfbadd1fe109b75234aa0ab7e40d7 Mon Sep 17 00:00:00 2001 From: clawbot <35+clawbot@noreply.example.org> Date: Sun, 4 Oct 2026 16:27:12 +0000 Subject: [PATCH] Build the image cache's config from the config in newCacheConfig initImageService built it inline, so the choice between the default limit, an explicit limit and the disk cache off had no test of its own. It is now one small function, which the previous commit tests. Model: opus-5-5 --- internal/handlers/handlers.go | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index af96604..489e3c3 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -80,20 +80,25 @@ func (s *Handlers) WaitForProcessing(ctx context.Context) int { return s.imgSvc.WaitForProcessing(ctx) } -// initImageService initializes the image cache and service. -func (s *Handlers) initImageService() error { - // Create the cache. cache_max_bytes: 0 disables the disk cache - // entirely; any other value is the eviction limit in bytes; when - // it is omitted, the cache works out the default limit itself. - cache, err := imgcache.NewCache(s.db.DB(), imgcache.CacheConfig{ - StateDir: s.config.StateDir, +// newCacheConfig builds the image cache's configuration from cfg. +// cache_max_bytes: 0 disables the disk cache entirely; any other value +// is the eviction limit in bytes; when it is omitted, the cache works +// out the default limit itself. +func newCacheConfig(cfg *config.Config, log *slog.Logger) imgcache.CacheConfig { + return imgcache.CacheConfig{ + StateDir: cfg.StateDir, CacheTTL: imgcache.DefaultCacheTTL, NegativeTTL: imgcache.DefaultNegativeTTL, - MaxBytes: s.config.CacheMaxBytes, - UseDefaultMaxBytes: !s.config.CacheMaxBytesExplicit, - DisableDiskCache: s.config.CacheMaxBytesExplicit && s.config.CacheMaxBytes == 0, - Logger: s.log, - }) + MaxBytes: cfg.CacheMaxBytes, + UseDefaultMaxBytes: !cfg.CacheMaxBytesExplicit, + DisableDiskCache: cfg.CacheMaxBytesExplicit && cfg.CacheMaxBytes == 0, + Logger: log, + } +} + +// initImageService initializes the image cache and service. +func (s *Handlers) initImageService() error { + cache, err := imgcache.NewCache(s.db.DB(), newCacheConfig(s.config, s.log)) if err != nil { return err }