Bug: Negative cache is never checked - checkNegativeCache is dead code #3

Closed
opened 2026-02-09 00:56:07 +01:00 by clawbot · 0 comments
Collaborator

Bug

The Cache.checkNegativeCache() method in internal/imgcache/cache.go is implemented but never called anywhere in the codebase. The Service.Get() method goes straight to Lookup() for variant cache, then to processFromSourceOrFetch(), without ever consulting the negative cache.

Meanwhile, StoreNegative() IS called from fetchAndProcess() when an upstream error occurs, so negative entries accumulate in the database but are never read.

Impact

Failed upstream fetches are re-attempted on every request instead of being short-circuited by the negative cache. This means:

  • Repeated requests for broken/404 images hammer the upstream server
  • The NegativeTTL configuration has no effect
  • Increased latency for known-bad URLs
  • The negative_cache table grows unbounded (only cleaned by CleanExpired which also isn't called regularly)

Fix

Add a negative cache check at the beginning of Service.Get(), before attempting to fetch from upstream. If the URL is in the negative cache, return an appropriate error immediately.

## Bug The `Cache.checkNegativeCache()` method in `internal/imgcache/cache.go` is implemented but never called anywhere in the codebase. The `Service.Get()` method goes straight to `Lookup()` for variant cache, then to `processFromSourceOrFetch()`, without ever consulting the negative cache. Meanwhile, `StoreNegative()` IS called from `fetchAndProcess()` when an upstream error occurs, so negative entries accumulate in the database but are never read. ## Impact Failed upstream fetches are re-attempted on every request instead of being short-circuited by the negative cache. This means: - Repeated requests for broken/404 images hammer the upstream server - The `NegativeTTL` configuration has no effect - Increased latency for known-bad URLs - The negative_cache table grows unbounded (only cleaned by `CleanExpired` which also isn't called regularly) ## Fix Add a negative cache check at the beginning of `Service.Get()`, before attempting to fetch from upstream. If the URL is in the negative cache, return an appropriate error immediately.
clawbot self-assigned this 2026-02-09 00:56:07 +01:00
sneak closed this issue 2026-02-09 01:32:27 +01:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sneak/pixa#3
No description provided.