@@ -20,11 +20,11 @@ import (
2020 "sync"
2121 "time"
2222
23+ "github.com/codeGROOVE-dev/fido"
24+ "github.com/codeGROOVE-dev/fido/pkg/store/cloudrun"
2325 "github.com/codeGROOVE-dev/gsm"
2426 "github.com/codeGROOVE-dev/prcost/pkg/cost"
2527 "github.com/codeGROOVE-dev/prcost/pkg/github"
26- "github.com/codeGROOVE-dev/sfcache"
27- "github.com/codeGROOVE-dev/sfcache/pkg/persist/cloudrun"
2828 "golang.org/x/time/rate"
2929)
3030
@@ -78,11 +78,11 @@ type Server struct {
7878 allowAllCors bool
7979 validateTokens bool
8080 r2rCallout bool
81- // Caching using sfcache (memory + optional persistence).
82- githubCache * sfcache .TieredCache [string , any ] // Unified 72h cache for all GitHub queries
83- prDataCache * sfcache .TieredCache [string , cost.PRData ] // 6-day cache for PR detail data
84- calcResultCache * sfcache .TieredCache [string , cost.Breakdown ] // 6-day cache for calculation results
85- githubClient * github.Client // Cached GitHub API client
81+ // Caching using fido (memory + optional persistence).
82+ githubCache * fido .TieredCache [string , any ] // Unified 72h cache for all GitHub queries
83+ prDataCache * fido .TieredCache [string , cost.PRData ] // 6-day cache for PR detail data
84+ calcResultCache * fido .TieredCache [string , cost.Breakdown ] // 6-day cache for calculation results
85+ githubClient * github.Client // Cached GitHub API client
8686}
8787
8888// CalculateRequest represents a request to calculate PR costs.
@@ -179,17 +179,17 @@ func New() *Server {
179179 dbName = "prcost"
180180 }
181181
182- // Initialize caches with sfcache (automatically handles memory + persistence).
182+ // Initialize caches with fido (automatically handles memory + persistence).
183183 // cloudrun.New uses Cloud Datastore when K_SERVICE is set (Cloud Run/Knative), local files otherwise.
184184 // Single unified cache with 72-hour TTL for all GitHub query results.
185185 githubPersist , err := cloudrun .New [string , any ](ctx , dbName )
186186 if err != nil {
187- logger .ErrorContext (ctx , "Failed to initialize GitHub cache persistence" , "error" , err )
187+ logger .ErrorContext (ctx , "Failed to initialize GitHub cache persistence" , "error" , err , "db" , dbName )
188188 return nil
189189 }
190- githubCache , err := sfcache .NewTiered [string , any ](githubPersist ,
191- sfcache .TTL (72 * time .Hour ),
192- sfcache .Size (2000 ),
190+ githubCache , err := fido .NewTiered [string , any ](githubPersist ,
191+ fido .TTL (72 * time .Hour ),
192+ fido .Size (2000 ),
193193 )
194194 if err != nil {
195195 logger .ErrorContext (ctx , "Failed to initialize GitHub cache" , "error" , err )
@@ -199,12 +199,12 @@ func New() *Server {
199199 // Separate caches for non-GitHub data with 6-day TTL
200200 prDataPersist , err := cloudrun .New [string , cost.PRData ](ctx , dbName )
201201 if err != nil {
202- logger .ErrorContext (ctx , "Failed to initialize PR data cache persistence" , "error" , err )
202+ logger .ErrorContext (ctx , "Failed to initialize PR data cache persistence" , "error" , err , "db" , dbName )
203203 return nil
204204 }
205- prDataCache , err := sfcache .NewTiered [string , cost.PRData ](prDataPersist ,
206- sfcache .TTL (6 * 24 * time .Hour ),
207- sfcache .Size (1000 ),
205+ prDataCache , err := fido .NewTiered [string , cost.PRData ](prDataPersist ,
206+ fido .TTL (6 * 24 * time .Hour ),
207+ fido .Size (1000 ),
208208 )
209209 if err != nil {
210210 logger .ErrorContext (ctx , "Failed to initialize PR data cache" , "error" , err )
@@ -213,12 +213,12 @@ func New() *Server {
213213
214214 calcResultPersist , err := cloudrun .New [string , cost.Breakdown ](ctx , dbName )
215215 if err != nil {
216- logger .ErrorContext (ctx , "Failed to initialize calc result cache persistence" , "error" , err )
216+ logger .ErrorContext (ctx , "Failed to initialize calc result cache persistence" , "error" , err , "db" , dbName )
217217 return nil
218218 }
219- calcResultCache , err := sfcache .NewTiered [string , cost.Breakdown ](calcResultPersist ,
220- sfcache .TTL (6 * 24 * time .Hour ),
221- sfcache .Size (1000 ),
219+ calcResultCache , err := fido .NewTiered [string , cost.Breakdown ](calcResultPersist ,
220+ fido .TTL (6 * 24 * time .Hour ),
221+ fido .Size (1000 ),
222222 )
223223 if err != nil {
224224 logger .ErrorContext (ctx , "Failed to initialize calc result cache" , "error" , err )
@@ -357,9 +357,9 @@ func (s *Server) limiter(ctx context.Context, ip string) *rate.Limiter {
357357 return lim
358358}
359359
360- // simpleCache implements github.Cache interface using a single sfcache [string, any].
360+ // simpleCache implements github.Cache interface using a single fido.TieredCache [string, any].
361361type simpleCache struct {
362- cache * sfcache .TieredCache [string , any ]
362+ cache * fido .TieredCache [string , any ]
363363 logger * slog.Logger
364364}
365365
@@ -370,44 +370,37 @@ func (s *simpleCache) Get(ctx context.Context, key string) (any, bool) {
370370 s .logger .WarnContext (ctx , "Cache error" , "key" , key , "error" , err )
371371 return nil , false
372372 }
373- if found {
374- s .logger .DebugContext (ctx , "Cache hit" , "key" , key )
375- }
376373 return val , found
377374}
378375
379376func (s * simpleCache ) Set (ctx context.Context , key string , value any ) {
380377 key = sanitizeCacheKey (key )
381- if err := s .cache .Set (ctx , key , value , 0 ); err != nil {
378+ if err := s .cache .Set (ctx , key , value ); err != nil {
382379 s .logger .WarnContext (ctx , "Failed to cache value" , "key" , key , "error" , err )
383380 }
384381}
385382
386- // cachedPRData retrieves cached PR data using sfcache .
383+ // cachedPRData retrieves cached PR data using fido .
387384func (s * Server ) cachedPRData (ctx context.Context , key string ) (cost.PRData , bool ) {
388385 key = sanitizeCacheKey (key )
389386 prData , found , err := s .prDataCache .Get (ctx , key )
390387 if err != nil {
391388 s .logger .WarnContext (ctx , "PR data cache error" , "key" , key , "error" , err )
392389 return cost.PRData {}, false
393390 }
394- if found {
395- s .logger .DebugContext (ctx , "PR data cache hit" , "key" , key )
396- }
397391 return prData , found
398392}
399393
400- // cachePRData stores PR data using sfcache .
394+ // cachePRData stores PR data using fido .
401395func (s * Server ) cachePRData (ctx context.Context , key string , prData cost.PRData ) {
402396 key = sanitizeCacheKey (key )
403- // Uses the default TTL configured during initialization (6 days)
404- if err := s .prDataCache .Set (ctx , key , prData , 0 ); err != nil {
397+ if err := s .prDataCache .Set (ctx , key , prData ); err != nil {
405398 s .logger .WarnContext (ctx , "Failed to cache PR data" , "key" , key , "error" , err )
406399 }
407400}
408401
409- // sanitizeCacheKey replaces characters not allowed by sfcache persistence layer.
410- // sfcache only allows: alphanumeric, dash, underscore, period, colon.
402+ // sanitizeCacheKey replaces characters not allowed by fido persistence layer.
403+ // fido only allows: alphanumeric, dash, underscore, period, colon.
411404// We replace: / with _ and = with -.
412405func sanitizeCacheKey (key string ) string {
413406 key = strings .ReplaceAll (key , "/" , "_" )
@@ -429,7 +422,7 @@ func configHash(cfg cost.Config) string {
429422 cfg .DeliveryDelayFactor )
430423}
431424
432- // cachedCalcResult retrieves cached calculation result using sfcache .
425+ // cachedCalcResult retrieves cached calculation result using fido .
433426func (s * Server ) cachedCalcResult (ctx context.Context , prURL string , cfg cost.Config ) (cost.Breakdown , bool ) {
434427 key := sanitizeCacheKey (fmt .Sprintf ("calc:%s:%s" , prURL , configHash (cfg )))
435428 breakdown , found , err := s .calcResultCache .Get (ctx , key )
@@ -440,11 +433,10 @@ func (s *Server) cachedCalcResult(ctx context.Context, prURL string, cfg cost.Co
440433 return breakdown , found
441434}
442435
443- // cacheCalcResult stores calculation result using sfcache .
436+ // cacheCalcResult stores calculation result using fido .
444437func (s * Server ) cacheCalcResult (ctx context.Context , prURL string , cfg cost.Config , b * cost.Breakdown ) {
445438 key := sanitizeCacheKey (fmt .Sprintf ("calc:%s:%s" , prURL , configHash (cfg )))
446- // Uses the default TTL configured during initialization (6 days)
447- if err := s .calcResultCache .Set (ctx , key , * b , 0 ); err != nil {
439+ if err := s .calcResultCache .Set (ctx , key , * b ); err != nil {
448440 s .logger .WarnContext (ctx , "Failed to cache calc result" , "key" , key , "error" , err )
449441 }
450442}
@@ -466,7 +458,7 @@ func (s *Server) SetTokenValidation(appID string, keyFile string) error {
466458// Shutdown gracefully shuts down the server.
467459func (s * Server ) Shutdown () {
468460 ctx := context .Background ()
469- // Close sfcache instances to flush any pending writes.
461+ // Close fido instances to flush any pending writes.
470462 if s .githubCache != nil {
471463 if err := s .githubCache .Close (); err != nil {
472464 s .logger .WarnContext (ctx , "Failed to close GitHub cache" , "error" , err )
0 commit comments