From d24f89f4f1bb7e1af5c12f7b849bbcad55b1f4e7 Mon Sep 17 00:00:00 2001 From: Adi Date: Thu, 25 Sep 2025 17:49:32 +0530 Subject: [PATCH] add sample data --- data/sample_data.json | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 data/sample_data.json diff --git a/data/sample_data.json b/data/sample_data.json new file mode 100644 index 0000000..c32144b --- /dev/null +++ b/data/sample_data.json @@ -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://: REDIS_PASSWORD= REDIS_DB= # 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"] + } + ] +}