Skip to content

Commit

Permalink
Fixed cache issue
Browse files Browse the repository at this point in the history
  • Loading branch information
day-mon committed Jan 16, 2024
1 parent 8092049 commit 613fbb7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
6 changes: 3 additions & 3 deletions api/api/business/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class RedisCache(Cache):
def __init__(self):
super().__init__()
self.redis_client = Redis(
host=self.cache_settings.HOST,
port=self.cache_settings.PORT,
db=self.cache_settings.NAME,
host=self.cache_settings.CACHE_HOST,
port=self.cache_settings.CACHE_PORT,
db=self.cache_settings.CACHE_NAME,
)
self.redis_client.ping()

Expand Down
13 changes: 6 additions & 7 deletions api/api/routes/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ async def list_models() -> list[str]:
},
)
async def predict(
# make sure its not blank
name: str = Path(..., title="Name of the model to use"),
name: str,
app_settings: AppSettings = Depends(get_settings),
cache_setting: CacheSettings = Depends(get_cache_settings),
) -> list[Prediction]:
Expand All @@ -64,13 +63,13 @@ async def predict(
if len(daily_games) == 0:
raise HTTPException(status_code=404, detail=f"No games found")

logger.debug(f"Caching is set to {cache_setting.TYPE}")
logger.debug(f"Caching is set to {cache_setting.CACHE_TYPE}")

if cache_setting.TYPE != "none":
if cache_setting.CACHE_TYPE != "none":
cache_key = get_cache_key(daily_games, name)
logger.debug(f"Using cache key {cache_key}")
cache = CacheFactory.compute_or_get(
name=cache_setting.TYPE,
name=cache_setting.CACHE_TYPE,
)
cached_predictions: Optional[str] = await cache.get(cache_key)
if cached_predictions:
Expand All @@ -90,11 +89,11 @@ async def predict(

stats: DataFrame = prediction_model.fetch_stats(daily_games=daily_games)
predictions: list[Prediction] = await prediction_model.predict(data=stats)
if cache_setting.TYPE != "none":
if cache_setting.CACHE_TYPE != "none":
cache_key = get_cache_key(daily_games, name)
logger.debug(f"Setting with key {cache_key}")
cache = CacheFactory.compute_or_get(
name=cache_setting.TYPE,
name=cache_setting.CACHE_TYPE,
)
predictions_json = [prediction.model_dump() for prediction in predictions]
predictions_json = json.dumps(predictions_json)
Expand Down

0 comments on commit 613fbb7

Please sign in to comment.