This pull request introduces a Redis-based caching mechanism to optimize the search functionality in the website. By caching search results, we aim to improve performance and reduce redundant database queries, especially for frequently searched terms.
Changes Made
RedisCache Class:
Added a RedisCache class to handle caching operations using Redis.
Configured the Redis client to use the Promise-based API for easier integration with async/await.
Implemented methods for setting, getting, invalidating, and clearing cache entries.
Search Endpoint Integration:
Integrated the caching mechanism into the search endpoint.
Before performing database queries, the endpoint checks if the search results are already cached. If cached results are found, they are returned immediately, reducing the load on the database. If no cached results are found, the search query is executed, and the results are processed and cached for future use.
Caching Logic:
Each search query, combined with the user ID, is used to generate a unique cache key.
The search results are cached with a configurable TTL (Time-To-Live), ensuring that stale data is eventually refreshed.
This pull request introduces a Redis-based caching mechanism to optimize the search functionality in the website. By caching search results, we aim to improve performance and reduce redundant database queries, especially for frequently searched terms.
Changes Made
RedisCache Class:
Search Endpoint Integration:
Caching Logic:
Project Demo:
Loom Message - 19 July 2024 - Watch Video