Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add redis caching #587

Merged
merged 9 commits into from
Jan 29, 2025
Merged

Add redis caching #587

merged 9 commits into from
Jan 29, 2025

Conversation

hugo-nl
Copy link
Collaborator

@hugo-nl hugo-nl commented Jan 27, 2025

Add Redis Caching

🌍 This PR introduces Redis-based caching for better performance and reduced database load.

Key Updates:
🌍 Companies API:
- Implements Redis cache with dynamic keys tied to latestMetadataUpdatedAt.
- Reduces redundant database queries by serving cached data when available.
🌍 Municipalities API:
- Adds Redis cache with a static key since data is immutable.
- Enhances performance with faster responses for repeated requests.

Benefits:
🌍 Optimized server performance.
🌍 Simplified cache management with automatic invalidation for updates.
🌍 Scalable design leveraging Redis.

🏠 Updated the readme with a quick setup for redis insight. Where you can inspect you redis data

Testing:
✅ Verified caching works for /companies and /municipalities APIs.
✅ Ensured no impact on existing ETag implementation.

Copy link
Collaborator

@Greenheart Greenheart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall a good improvement!

Some important things to consider and resolve before merging.

src/api/schemas/response.ts Outdated Show resolved Hide resolved
.openapi({ description: 'Start date of reporting period' }),
endDate: z.date().openapi({ description: 'End date of reporting period' }),
endDate: z
.union([z.date(), z.string()])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here with the z.string().date()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👆

src/createCache.ts Outdated Show resolved Hide resolved
src/createCache.ts Outdated Show resolved Hide resolved
src/api/schemas/response.ts Outdated Show resolved Hide resolved
@hugo-nl hugo-nl requested a review from Greenheart January 28, 2025 09:12
Copy link
Collaborator

@Greenheart Greenheart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for these improvements! Good thing we fixed the cache key before deploying 😄

@Greenheart Greenheart merged commit 8a8571f into staging Jan 29, 2025
@Greenheart Greenheart deleted the add-redis-caching branch January 29, 2025 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants