Count what the cache holds in the default cache_max_bytes (closes #184) #188
@@ -80,20 +80,25 @@ func (s *Handlers) WaitForProcessing(ctx context.Context) int {
|
|||||||
return s.imgSvc.WaitForProcessing(ctx)
|
return s.imgSvc.WaitForProcessing(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// initImageService initializes the image cache and service.
|
// newCacheConfig builds the image cache's configuration from cfg.
|
||||||
func (s *Handlers) initImageService() error {
|
// cache_max_bytes: 0 disables the disk cache entirely; any other value
|
||||||
// Create the cache. cache_max_bytes: 0 disables the disk cache
|
// is the eviction limit in bytes; when it is omitted, the cache works
|
||||||
// entirely; any other value is the eviction limit in bytes; when
|
// out the default limit itself.
|
||||||
// it is omitted, the cache works out the default limit itself.
|
func newCacheConfig(cfg *config.Config, log *slog.Logger) imgcache.CacheConfig {
|
||||||
cache, err := imgcache.NewCache(s.db.DB(), imgcache.CacheConfig{
|
return imgcache.CacheConfig{
|
||||||
StateDir: s.config.StateDir,
|
StateDir: cfg.StateDir,
|
||||||
CacheTTL: imgcache.DefaultCacheTTL,
|
CacheTTL: imgcache.DefaultCacheTTL,
|
||||||
NegativeTTL: imgcache.DefaultNegativeTTL,
|
NegativeTTL: imgcache.DefaultNegativeTTL,
|
||||||
MaxBytes: s.config.CacheMaxBytes,
|
MaxBytes: cfg.CacheMaxBytes,
|
||||||
UseDefaultMaxBytes: !s.config.CacheMaxBytesExplicit,
|
UseDefaultMaxBytes: !cfg.CacheMaxBytesExplicit,
|
||||||
DisableDiskCache: s.config.CacheMaxBytesExplicit && s.config.CacheMaxBytes == 0,
|
DisableDiskCache: cfg.CacheMaxBytesExplicit && cfg.CacheMaxBytes == 0,
|
||||||
Logger: s.log,
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user