Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions data/sample_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"doc": "### Redis Caching – Movie Details We cache only the **Search by ID** results in Redis to reduce API calls to OMDb and improve response time. **Caching Strategy:** - Cache Key: `movie_[imdb_id]` - TTL (Time-To-Live): 1 hour - Stored Value: Serialized JSON of `MovieDetails` DTO --- ### Environment Variables To connect to a cloud Redis instance, the following environment variables should be set: ```env REDIS_URL=redis://<host>:<port> REDIS_PASSWORD=<password> REDIS_DB=<db_index> # optional, default 0 CACHE_TTL=3600 # default 1 hour ``` --- ### Function Signatures ```python from pydantic import BaseModel from typing import Optional def cache_movie(movie_id: str, movie_obj: BaseModel) -> None: \"\"\" Stores the movie details in Redis under the key `movie_[movie_id]`. TTL is set to 1 hour. \"\"\" def get_movie(movie_id: str) -> Optional[BaseModel]: \"\"\" Retrieves the cached movie details from Redis. Returns None if the key does not exist. \"\"\" ``` --- ### Additional Setup Guidance 1. **Python Redis Client:** - Use the official `redis-py` package. - Example: `pip install redis` 2. **Connection Setup:** - Initialize Redis client with environment variables. - Always handle connection errors gracefully. 3. **Error Handling:** - If the Redis connection fails at app startup, log the error and exit the application. - This ensures the app does not run with missing caching infrastructure. 4. **Best Practices:** - Use a consistent key naming convention (`movie_[imdb_id]`). - Set TTL for all cached keys to avoid stale data. - Consider a monitoring solution to track cache hits/misses.",
"issues": [
{
"title": "Task 4.1: Redis Connection Setup",
"body": "- [ ] Create Redis client initialization with connection pool\n- [ ] Implement connection health check on app startup\n- [ ] Add graceful error handling for Redis connection failures\n\n**Sprint:** 4 - Caching Layer\n**Dependencies:** Environment Configuration (Task 1.2)\n**Documentation:** caching.md - Environment Variables and Setup Guidance",
"labels": ["caching", "redis"],
"dependency": []
},
{
"title": "Task 4.2: Cache Service Implementation",
"body": "- [ ] Implement cache_movie() function with TTL support\n- [ ] Create get_movie() function to retrieve cached data\n- [ ] Add JSON serialization/deserialization for MovieDetails\n\n**Sprint:** 4 - Caching Layer\n**Dependencies:** Movie Detail Models (Task 2.3)\n**Documentation:** caching.md - Function Signatures section",
"labels": ["caching", "redis"],
"dependency": ["Task 4.1: Redis Connection Setup"]
},
{
"title": "Task 4.3: Cache Integration",
"body": "- [ ] Integrate caching into movie details endpoint\n- [ ] Add cache hit/miss logging\n- [ ] Implement cache key naming convention (movie_[imdb_id])\n\n**In short:** Create a main `get_movie` method that checks for cache, if not found then makes the api call using the OMDb client, caches it and then returns it.\n\n**Sprint:** 4 - Caching Layer\n**Dependencies:** Redis Connection Setup (Task 4.1), Cache Service Implementation (Task 4.2)\n**Documentation:** caching.md - full document",
"labels": ["caching", "redis"],
"dependency": ["Task 4.1: Redis Connection Setup", "Task 4.2: Cache Service Implementation"]
}
]
}