@@ -20,8 +20,8 @@ import (
2020 "sync"
2121 "time"
2222
23- "github.com/codeGROOVE-dev/bdcache "
24- "github.com/codeGROOVE-dev/bdcache /persist/cloudrun"
23+ "github.com/codeGROOVE-dev/sfcache "
24+ "github.com/codeGROOVE-dev/sfcache/pkg /persist/cloudrun"
2525 "github.com/codeGROOVE-dev/gsm"
2626 "github.com/codeGROOVE-dev/prcost/pkg/cost"
2727 "github.com/codeGROOVE-dev/prcost/pkg/github"
@@ -78,10 +78,10 @@ type Server struct {
7878 allowAllCors bool
7979 validateTokens bool
8080 r2rCallout bool
81- // Caching using bdcache (memory + optional persistence).
82- githubCache * bdcache. Cache [string , any ] // Unified 72h cache for all GitHub queries
83- prDataCache * bdcache. Cache [string , cost.PRData ] // 6-day cache for PR detail data
84- calcResultCache * bdcache. Cache [string , cost.Breakdown ] // 6-day cache for calculation results
81+ // Caching using sfcache (memory + optional persistence).
82+ githubCache * sfcache. PersistentCache [string , any ] // Unified 72h cache for all GitHub queries
83+ prDataCache * sfcache. PersistentCache [string , cost.PRData ] // 6-day cache for PR detail data
84+ calcResultCache * sfcache. PersistentCache [string , cost.Breakdown ] // 6-day cache for calculation results
8585 githubClient * github.Client // Cached GitHub API client
8686}
8787
@@ -179,18 +179,17 @@ func New() *Server {
179179 dbName = "prcost"
180180 }
181181
182- // Initialize caches with bdcache (automatically handles memory + persistence).
182+ // Initialize caches with sfcache (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 {
187187 logger .ErrorContext (ctx , "Failed to initialize GitHub cache persistence" , "error" , err )
188188 return nil
189189 }
190- githubCache , err := bdcache .New [string , any ](ctx ,
191- bdcache .WithPersistence (githubPersist ),
192- bdcache .WithDefaultTTL (72 * time .Hour ),
193- bdcache .WithMemorySize (2000 ),
190+ githubCache , err := sfcache .Persistent [string , any ](ctx , githubPersist ,
191+ sfcache .WithTTL (72 * time .Hour ),
192+ sfcache .WithSize (2000 ),
194193 )
195194 if err != nil {
196195 logger .ErrorContext (ctx , "Failed to initialize GitHub cache" , "error" , err )
@@ -203,10 +202,9 @@ func New() *Server {
203202 logger .ErrorContext (ctx , "Failed to initialize PR data cache persistence" , "error" , err )
204203 return nil
205204 }
206- prDataCache , err := bdcache .New [string , cost.PRData ](ctx ,
207- bdcache .WithPersistence (prDataPersist ),
208- bdcache .WithDefaultTTL (6 * 24 * time .Hour ),
209- bdcache .WithMemorySize (1000 ),
205+ prDataCache , err := sfcache .Persistent [string , cost.PRData ](ctx , prDataPersist ,
206+ sfcache .WithTTL (6 * 24 * time .Hour ),
207+ sfcache .WithSize (1000 ),
210208 )
211209 if err != nil {
212210 logger .ErrorContext (ctx , "Failed to initialize PR data cache" , "error" , err )
@@ -218,10 +216,9 @@ func New() *Server {
218216 logger .ErrorContext (ctx , "Failed to initialize calc result cache persistence" , "error" , err )
219217 return nil
220218 }
221- calcResultCache , err := bdcache .New [string , cost.Breakdown ](ctx ,
222- bdcache .WithPersistence (calcResultPersist ),
223- bdcache .WithDefaultTTL (6 * 24 * time .Hour ),
224- bdcache .WithMemorySize (1000 ),
219+ calcResultCache , err := sfcache .Persistent [string , cost.Breakdown ](ctx , calcResultPersist ,
220+ sfcache .WithTTL (6 * 24 * time .Hour ),
221+ sfcache .WithSize (1000 ),
225222 )
226223 if err != nil {
227224 logger .ErrorContext (ctx , "Failed to initialize calc result cache" , "error" , err )
@@ -360,9 +357,9 @@ func (s *Server) limiter(ctx context.Context, ip string) *rate.Limiter {
360357 return limiter
361358}
362359
363- // simpleCache implements github.Cache interface using a single bdcache [string, any].
360+ // simpleCache implements github.Cache interface using a single sfcache [string, any].
364361type simpleCache struct {
365- cache * bdcache. Cache [string , any ]
362+ cache * sfcache. PersistentCache [string , any ]
366363 logger * slog.Logger
367364}
368365
@@ -386,7 +383,7 @@ func (s *simpleCache) Set(ctx context.Context, key string, value any) {
386383 }
387384}
388385
389- // cachedPRData retrieves cached PR data using bdcache .
386+ // cachedPRData retrieves cached PR data using sfcache .
390387func (s * Server ) cachedPRData (ctx context.Context , key string ) (cost.PRData , bool ) {
391388 key = sanitizeCacheKey (key )
392389 prData , found , err := s .prDataCache .Get (ctx , key )
@@ -400,7 +397,7 @@ func (s *Server) cachedPRData(ctx context.Context, key string) (cost.PRData, boo
400397 return prData , found
401398}
402399
403- // cachePRData stores PR data using bdcache .
400+ // cachePRData stores PR data using sfcache .
404401func (s * Server ) cachePRData (ctx context.Context , key string , prData cost.PRData ) {
405402 key = sanitizeCacheKey (key )
406403 // Uses the default TTL configured during initialization (6 days)
@@ -409,8 +406,8 @@ func (s *Server) cachePRData(ctx context.Context, key string, prData cost.PRData
409406 }
410407}
411408
412- // sanitizeCacheKey replaces characters not allowed by bdcache persistence layer.
413- // bdcache only allows: alphanumeric, dash, underscore, period, colon.
409+ // sanitizeCacheKey replaces characters not allowed by sfcache persistence layer.
410+ // sfcache only allows: alphanumeric, dash, underscore, period, colon.
414411// We replace: / with _ and = with -.
415412func sanitizeCacheKey (key string ) string {
416413 key = strings .ReplaceAll (key , "/" , "_" )
@@ -432,7 +429,7 @@ func configHash(cfg cost.Config) string {
432429 cfg .DeliveryDelayFactor )
433430}
434431
435- // cachedCalcResult retrieves cached calculation result using bdcache .
432+ // cachedCalcResult retrieves cached calculation result using sfcache .
436433func (s * Server ) cachedCalcResult (ctx context.Context , prURL string , cfg cost.Config ) (cost.Breakdown , bool ) {
437434 key := sanitizeCacheKey (fmt .Sprintf ("calc:%s:%s" , prURL , configHash (cfg )))
438435 breakdown , found , err := s .calcResultCache .Get (ctx , key )
@@ -443,7 +440,7 @@ func (s *Server) cachedCalcResult(ctx context.Context, prURL string, cfg cost.Co
443440 return breakdown , found
444441}
445442
446- // cacheCalcResult stores calculation result using bdcache .
443+ // cacheCalcResult stores calculation result using sfcache .
447444func (s * Server ) cacheCalcResult (ctx context.Context , prURL string , cfg cost.Config , b * cost.Breakdown ) {
448445 key := sanitizeCacheKey (fmt .Sprintf ("calc:%s:%s" , prURL , configHash (cfg )))
449446 // Uses the default TTL configured during initialization (6 days)
@@ -469,7 +466,7 @@ func (s *Server) SetTokenValidation(appID string, keyFile string) error {
469466// Shutdown gracefully shuts down the server.
470467func (s * Server ) Shutdown () {
471468 ctx := context .Background ()
472- // Close bdcache instances to flush any pending writes.
469+ // Close sfcache instances to flush any pending writes.
473470 if s .githubCache != nil {
474471 if err := s .githubCache .Close (); err != nil {
475472 s .logger .WarnContext (ctx , "Failed to close GitHub cache" , "error" , err )
0 commit comments