Skip to content

Commit

Permalink
feat(minor): rename some cache functions
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Gleich <[email protected]>
  • Loading branch information
gleich committed Dec 29, 2024
1 parent f913a52 commit 423dfaa
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions internal/apis/applemusic/applemusic.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func Setup(router *chi.Mux) {
lumber.Fatal(err, "initial fetch of cache data failed")
}

applemusicCache := cache.NewCache("applemusic", data)
applemusicCache := cache.New("applemusic", data)
router.Get("/applemusic/cache", applemusicCache.ServeHTTP())
router.Handle("/applemusic/cache/ws", applemusicCache.ServeWS())
go applemusicCache.StartPeriodicUpdate(cacheUpdate, 30*time.Second)
go applemusicCache.PeriodicUpdate(cacheUpdate, 30*time.Second)
lumber.Done("setup apple music cache")
}
4 changes: 2 additions & 2 deletions internal/apis/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ func Setup(router *chi.Mux) {
lumber.Fatal(err, "fetching initial pinned repos failed")
}

githubCache := cache.NewCache("github", pinnedRepos)
githubCache := cache.New("github", pinnedRepos)
router.Get("/github/cache", githubCache.ServeHTTP())
router.Handle("/github/cache/ws", githubCache.ServeWS())
go githubCache.StartPeriodicUpdate(
go githubCache.PeriodicUpdate(
func() ([]repository, error) { return fetchPinnedRepos(githubClient) },
2*time.Minute,
)
Expand Down
4 changes: 2 additions & 2 deletions internal/apis/steam/steam.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ func Setup(router *chi.Mux) {
lumber.Fatal(err, "initial fetch of games failed")
}

steamCache := cache.NewCache("steam", games)
steamCache := cache.New("steam", games)
router.Get("/steam/cache", steamCache.ServeHTTP())
router.Handle("/steam/cache/ws", steamCache.ServeWS())
go steamCache.StartPeriodicUpdate(fetchRecentlyPlayedGames, 5*time.Minute)
go steamCache.PeriodicUpdate(fetchRecentlyPlayedGames, 5*time.Minute)
lumber.Done("setup steam cache")
}
2 changes: 1 addition & 1 deletion internal/apis/strava/strava.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func Setup(router *chi.Mux) {
if err != nil {
lumber.ErrorMsg("failed to load initial data for strava cache; not updating")
}
stravaCache := cache.NewCache("strava", stravaActivities)
stravaCache := cache.New("strava", stravaActivities)
router.Get("/strava/cache", stravaCache.ServeHTTP())
router.Handle("/strava/cache/ws", stravaCache.ServeWS())
router.Post("/strava/event", eventRoute(stravaCache, *minioClient, stravaTokens))
Expand Down
4 changes: 2 additions & 2 deletions internal/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Cache[T any] struct {
wsUpgrader websocket.Upgrader
}

func NewCache[T any](name string, data T) *Cache[T] {
func New[T any](name string, data T) *Cache[T] {
cache := Cache[T]{
name: name,
updateCounter: promauto.NewCounter(prometheus.CounterOpts{
Expand Down Expand Up @@ -115,7 +115,7 @@ func (c *Cache[T]) Update(data T) {
}
}

func (c *Cache[T]) StartPeriodicUpdate(updateFunc func() (T, error), interval time.Duration) {
func (c *Cache[T]) PeriodicUpdate(updateFunc func() (T, error), interval time.Duration) {
ticker := time.NewTicker(interval)
defer ticker.Stop()
for range ticker.C {
Expand Down

0 comments on commit 423dfaa

Please sign in to comment.