@@ -35,6 +35,13 @@ func (app *App) turnData(ctx context.Context, url string, updatedAt time.Time) (
3535 hash := sha256 .Sum256 ([]byte (key ))
3636 cacheFile := filepath .Join (app .cacheDir , hex .EncodeToString (hash [:])[:16 ]+ ".json" )
3737
38+ // Log the cache key details
39+ slog .Debug ("[CACHE] Checking cache" ,
40+ "url" , url ,
41+ "updated_at" , updatedAt .Format (time .RFC3339 ),
42+ "cache_key" , key ,
43+ "cache_file" , filepath .Base (cacheFile ))
44+
3845 // Skip cache if --no-cache flag is set
3946 if ! app .noCache {
4047 // Try to read from cache (gracefully handle all cache errors)
@@ -47,17 +54,46 @@ func (app *App) turnData(ctx context.Context, url string, updatedAt time.Time) (
4754 slog .Error ("Failed to remove corrupted cache file" , "error" , removeErr )
4855 }
4956 } else if time .Since (entry .CachedAt ) < cacheTTL && entry .UpdatedAt .Equal (updatedAt ) {
50- // Check if cache is still valid (2 hour TTL)
57+ // Check if cache is still valid (10 day TTL, but PR UpdatedAt is primary check)
58+ slog .Debug ("[CACHE] Cache hit" ,
59+ "url" , url ,
60+ "cached_at" , entry .CachedAt .Format (time .RFC3339 ),
61+ "cache_age" , time .Since (entry .CachedAt ).Round (time .Second ),
62+ "pr_updated_at" , entry .UpdatedAt .Format (time .RFC3339 ))
63+ if app .healthMonitor != nil {
64+ app .healthMonitor .recordCacheAccess (true )
65+ }
5166 return entry .Data , true , nil
67+ } else {
68+ // Log why cache was invalid
69+ if ! entry .UpdatedAt .Equal (updatedAt ) {
70+ slog .Debug ("[CACHE] Cache miss - PR updated" ,
71+ "url" , url ,
72+ "cached_pr_time" , entry .UpdatedAt .Format (time .RFC3339 ),
73+ "current_pr_time" , updatedAt .Format (time .RFC3339 ))
74+ } else if time .Since (entry .CachedAt ) >= cacheTTL {
75+ slog .Debug ("[CACHE] Cache miss - TTL expired" ,
76+ "url" , url ,
77+ "cached_at" , entry .CachedAt .Format (time .RFC3339 ),
78+ "cache_age" , time .Since (entry .CachedAt ).Round (time .Second ),
79+ "ttl" , cacheTTL )
80+ }
5281 }
82+ } else if ! os .IsNotExist (readErr ) {
83+ slog .Debug ("[CACHE] Cache file read error" , "url" , url , "error" , readErr )
5384 }
5485 }
5586
5687 // Cache miss, fetch from API
5788 if app .noCache {
5889 slog .Debug ("Cache bypassed (--no-cache), fetching from Turn API" , "url" , url )
5990 } else {
60- slog .Debug ("Cache miss, fetching from Turn API" , "url" , url )
91+ slog .Info ("[CACHE] Cache miss, fetching from Turn API" ,
92+ "url" , url ,
93+ "pr_updated_at" , updatedAt .Format (time .RFC3339 ))
94+ if app .healthMonitor != nil {
95+ app .healthMonitor .recordCacheAccess (false )
96+ }
6197 }
6298
6399 // Use exponential backoff with jitter for Turn API calls
@@ -68,11 +104,16 @@ func (app *App) turnData(ctx context.Context, url string, updatedAt time.Time) (
68104 defer cancel ()
69105
70106 var retryErr error
107+ slog .Debug ("[TURN] Making API call" ,
108+ "url" , url ,
109+ "user" , app .currentUser .GetLogin (),
110+ "pr_updated_at" , updatedAt .Format (time .RFC3339 ))
71111 data , retryErr = app .turnClient .Check (turnCtx , url , app .currentUser .GetLogin (), updatedAt )
72112 if retryErr != nil {
73113 slog .Warn ("Turn API error (will retry)" , "error" , retryErr )
74114 return retryErr
75115 }
116+ slog .Debug ("[TURN] API call successful" , "url" , url )
76117 return nil
77118 },
78119 retry .Attempts (maxRetries ),
@@ -85,9 +126,16 @@ func (app *App) turnData(ctx context.Context, url string, updatedAt time.Time) (
85126 )
86127 if err != nil {
87128 slog .Error ("Turn API error after retries (will use PR without metadata)" , "maxRetries" , maxRetries , "error" , err )
129+ if app .healthMonitor != nil {
130+ app .healthMonitor .recordAPICall (false )
131+ }
88132 return nil , false , err
89133 }
90134
135+ if app .healthMonitor != nil {
136+ app .healthMonitor .recordAPICall (true )
137+ }
138+
91139 // Save to cache (don't fail if caching fails) - skip if --no-cache is set
92140 if ! app .noCache {
93141 entry := cacheEntry {
@@ -103,14 +151,20 @@ func (app *App) turnData(ctx context.Context, url string, updatedAt time.Time) (
103151 slog .Error ("Failed to create cache directory" , "error" , dirErr )
104152 } else if writeErr := os .WriteFile (cacheFile , cacheData , 0o600 ); writeErr != nil {
105153 slog .Error ("Failed to write cache file" , "error" , writeErr )
154+ } else {
155+ slog .Debug ("[CACHE] Saved to cache" ,
156+ "url" , url ,
157+ "cached_at" , entry .CachedAt .Format (time .RFC3339 ),
158+ "pr_updated_at" , entry .UpdatedAt .Format (time .RFC3339 ),
159+ "cache_file" , filepath .Base (cacheFile ))
106160 }
107161 }
108162 }
109163
110164 return data , false , nil
111165}
112166
113- // cleanupOldCache removes cache files older than 5 days.
167+ // cleanupOldCache removes cache files older than the cleanup interval (15 days) .
114168func (app * App ) cleanupOldCache () {
115169 entries , err := os .ReadDir (app .cacheDir )
116170 if err != nil {
@@ -131,7 +185,7 @@ func (app *App) cleanupOldCache() {
131185 continue
132186 }
133187
134- // Remove cache files older than 5 days
188+ // Remove cache files older than cleanup interval (15 days)
135189 if time .Since (info .ModTime ()) > cacheCleanupInterval {
136190 filePath := filepath .Join (app .cacheDir , entry .Name ())
137191 if removeErr := os .Remove (filePath ); removeErr != nil {
0 commit comments