@@ -17,9 +17,9 @@ import (
1717 "strings"
1818 "time"
1919
20+ "github.com/codeGROOVE-dev/fido"
21+ "github.com/codeGROOVE-dev/fido/pkg/store/localfs"
2022 "github.com/codeGROOVE-dev/prx/pkg/prx/github"
21- "github.com/codeGROOVE-dev/sfcache"
22- "github.com/codeGROOVE-dev/sfcache/pkg/store/localfs"
2323)
2424
2525const (
@@ -29,20 +29,30 @@ const (
2929 idleConnTimeoutSec = 90
3030
3131 // Cache TTL constants.
32- prCacheTTL = 20 * 24 * time .Hour // 20 days
33- collaboratorsCacheTTL = 4 * time .Hour
32+ prCacheTTL = 20 * 24 * time .Hour // 20 days - validity checked against reference time
33+ checkRunsCacheTTL = 20 * 24 * time .Hour // 20 days - validity checked against reference time
34+ collaboratorsCacheTTL = 3 * time .Hour // 3 hours - repo-level, simple TTL
35+ rulesetsCacheTTL = 3 * time .Hour // 3 hours - repo-level, simple TTL
3436)
3537
38+ // cachedCheckRuns stores check run events with a timestamp for cache validation.
39+ type cachedCheckRuns struct {
40+ CachedAt time.Time
41+ Events []Event
42+ }
43+
3644// PRStore is the interface for PR cache storage backends.
37- // This is an alias for sfcache .Store with the appropriate type parameters.
38- type PRStore = sfcache .Store [string , PullRequestData ]
45+ // This is an alias for fido .Store with the appropriate type parameters.
46+ type PRStore = fido .Store [string , PullRequestData ]
3947
4048// Client provides methods to fetch GitHub pull request events.
4149type Client struct {
4250 github * github.Client
4351 logger * slog.Logger
44- collaboratorsCache * sfcache.MemoryCache [string , map [string ]string ]
45- prCache * sfcache.TieredCache [string , PullRequestData ]
52+ collaboratorsCache * fido.Cache [string , map [string ]string ]
53+ rulesetsCache * fido.Cache [string , []string ]
54+ checkRunsCache * fido.Cache [string , cachedCheckRuns ]
55+ prCache * fido.TieredCache [string , PullRequestData ]
4656 token string // Store token for recreating client with new transport
4757}
4858
@@ -73,7 +83,7 @@ func WithHTTPClient(httpClient *http.Client) Option {
7383// Use null.New[string, prx.PullRequestData]() to disable persistence.
7484func WithCacheStore (store PRStore ) Option {
7585 return func (c * Client ) {
76- prCache , err := sfcache .NewTiered (store , sfcache .TTL (prCacheTTL ))
86+ prCache , err := fido .NewTiered (store , fido .TTL (prCacheTTL ))
7787 if err != nil {
7888 c .logger .Warn ("failed to create cache from store, using default" , "error" , err )
7989 return
@@ -97,7 +107,9 @@ func NewClient(token string, opts ...Option) *Client {
97107 c := & Client {
98108 logger : slog .Default (),
99109 token : token ,
100- collaboratorsCache : sfcache.New [string , map [string ]string ](sfcache .TTL (collaboratorsCacheTTL )),
110+ collaboratorsCache : fido.New [string , map [string ]string ](fido .TTL (collaboratorsCacheTTL )),
111+ rulesetsCache : fido.New [string , []string ](fido .TTL (rulesetsCacheTTL )),
112+ checkRunsCache : fido.New [string , cachedCheckRuns ](fido .TTL (checkRunsCacheTTL )),
101113 github : newGitHubClient (
102114 & http.Client {
103115 Transport : & github.Transport {Base : transport },
@@ -120,7 +132,7 @@ func NewClient(token string, opts ...Option) *Client {
120132 return c
121133}
122134
123- func createDefaultCache (log * slog.Logger ) * sfcache .TieredCache [string , PullRequestData ] {
135+ func createDefaultCache (log * slog.Logger ) * fido .TieredCache [string , PullRequestData ] {
124136 dir , err := os .UserCacheDir ()
125137 if err != nil {
126138 dir = os .TempDir ()
@@ -135,7 +147,7 @@ func createDefaultCache(log *slog.Logger) *sfcache.TieredCache[string, PullReque
135147 log .Warn ("failed to create cache store, caching disabled" , "error" , err )
136148 return nil
137149 }
138- cache , err := sfcache .NewTiered (store , sfcache .TTL (prCacheTTL ))
150+ cache , err := fido .NewTiered (store , fido .TTL (prCacheTTL ))
139151 if err != nil {
140152 log .Warn ("failed to create cache, caching disabled" , "error" , err )
141153 return nil
@@ -156,7 +168,7 @@ func (c *Client) PullRequestWithReferenceTime(
156168 refTime time.Time ,
157169) (* PullRequestData , error ) {
158170 if c .prCache == nil {
159- return c .pullRequestViaGraphQL (ctx , owner , repo , pr )
171+ return c .pullRequestViaGraphQL (ctx , owner , repo , pr , refTime )
160172 }
161173
162174 key := prCacheKey (owner , repo , pr )
@@ -180,8 +192,8 @@ func (c *Client) PullRequestWithReferenceTime(
180192 "owner" , owner , "repo" , repo , "pr" , pr )
181193 }
182194
183- result , err := c .prCache .GetSet (ctx , key , func (ctx context.Context ) (PullRequestData , error ) {
184- data , err := c .pullRequestViaGraphQL (ctx , owner , repo , pr )
195+ result , err := c .prCache .Fetch (ctx , key , func (ctx context.Context ) (PullRequestData , error ) {
196+ data , err := c .pullRequestViaGraphQL (ctx , owner , repo , pr , refTime )
185197 if err != nil {
186198 return PullRequestData {}, err
187199 }
@@ -230,3 +242,13 @@ func prCacheKey(owner, repo string, prNumber int) string {
230242func collaboratorsCacheKey (owner , repo string ) string {
231243 return fmt .Sprintf ("%s/%s" , owner , repo )
232244}
245+
246+ // rulesetsCacheKey generates a cache key for rulesets data.
247+ func rulesetsCacheKey (owner , repo string ) string {
248+ return fmt .Sprintf ("%s/%s" , owner , repo )
249+ }
250+
251+ // checkRunsCacheKey generates a cache key for check runs data.
252+ func checkRunsCacheKey (owner , repo , sha string ) string {
253+ return fmt .Sprintf ("%s/%s/%s" , owner , repo , sha )
254+ }
0 commit comments