Skip to content

Commit

Permalink
extract cacheKey to variable
Browse files Browse the repository at this point in the history
  • Loading branch information
joschahenningsen committed Nov 8, 2024
1 parent 7b2adda commit 89ccbf2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions server/backend/movie.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func (s *CampusServer) ListMovies(ctx context.Context, req *pb.ListMoviesRequest
}

func (s *CampusServer) getMovies(ctx context.Context, lastID int32, oldestDateAt time.Time) ([]model.Movie, error) {
if movies, ok := s.moviesCache.Get(fmt.Sprintf("%d-%d", lastID, oldestDateAt.Second())); ok {
cacheKey := fmt.Sprintf("%d-%d", lastID, oldestDateAt.Second())
if movies, ok := s.moviesCache.Get(cacheKey); ok {
return movies, nil
}
var movies []model.Movie
Expand All @@ -58,6 +59,6 @@ func (s *CampusServer) getMovies(ctx context.Context, lastID int32, oldestDateAt
log.WithError(err).Error("Error while fetching movies from database")
return nil, status.Error(codes.Internal, "Error while fetching movies from database")
}
s.moviesCache.Add(fmt.Sprintf("%d-%d", lastID, oldestDateAt.Second()), movies)
s.moviesCache.Add(cacheKey, movies)
return movies, nil
}

0 comments on commit 89ccbf2

Please sign in to comment.