From 108464b313f13688b74883dfb3c4f53e2f5bbc6e Mon Sep 17 00:00:00 2001 From: Djeex Date: Fri, 5 Dec 2025 16:12:57 +0100 Subject: [PATCH] Fixed cache issues --- app/env_config.py | 6 +++++- app/gpu_checker.py | 21 +++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/env_config.py b/app/env_config.py index 7599a0d..55f3354 100644 --- a/app/env_config.py +++ b/app/env_config.py @@ -89,7 +89,11 @@ HEADERS = { "Sec-Fetch-Dest": "empty", "Sec-Fetch-Mode": "cors", "Sec-Ch-Ua": "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not.A/Brand\";v=\"24\"", - "Sec-Ch-Ua-Platform": "\"macOS\"" + "Sec-Ch-Ua-Platform": "\"macOS\"", + # Headers anti-cache pour forcer la récupération de données fraîches + "Cache-Control": "no-cache, no-store, must-revalidate", + "Pragma": "no-cache", + "Expires": "0" } # Load country setting and localization config diff --git a/app/gpu_checker.py b/app/gpu_checker.py index 3434ba0..ff0964d 100644 --- a/app/gpu_checker.py +++ b/app/gpu_checker.py @@ -1,14 +1,18 @@ import requests import logging +import time from env_config import HEADERS, PRODUCT_NAMES, API_URL_SKU, API_URL_STOCK, PRODUCT_URL from notifier import send_discord_notification, send_out_of_stock_notification, send_sku_change_notification from requests.adapters import HTTPAdapter, Retry -# HTTP session +# HTTP session avec configuration anti-cache session = requests.Session() retries = Retry(total=5, backoff_factor=1, status_forcelist=[500, 502, 503, 504]) session.mount('https://', HTTPAdapter(max_retries=retries)) +# Configuration de la session pour éviter le cache +session.headers.update(HEADERS) + # Keeping memory of last run last_sku_dict = {} global_stock_status_dict = {} @@ -18,9 +22,13 @@ first_run_dict = {name: True for name in PRODUCT_NAMES} def check_rtx_50_founders(): global last_sku_dict, global_stock_status_dict, first_run_dict - # Fetching nvidia API data + # Fetching nvidia API data avec timestamp anti-cache try: - response = session.get(API_URL_SKU, headers=HEADERS, timeout=10) + # Ajout d'un paramètre timestamp pour éviter le cache + cache_buster = int(time.time() * 1000) # timestamp en millisecondes + sku_url = f"{API_URL_SKU}&_t={cache_buster}" + + response = session.get(sku_url, timeout=10) logging.info(f"SKU API response: {response.status_code}") response.raise_for_status() data = response.json() @@ -56,12 +64,13 @@ def check_rtx_50_founders(): last_sku_dict[product_name] = product_sku first_run_dict[product_name] = False - # Check product availability in API_URL_STOCK for each SKU - api_stock_url = API_URL_STOCK + product_sku + # Check product availability in API_URL_STOCK for each SKU avec cache buster + cache_buster = int(time.time() * 1000) # timestamp en millisecondes + api_stock_url = f"{API_URL_STOCK}{product_sku}&_t={cache_buster}" logging.info(f"[{product_name}] Checking stock: {api_stock_url}") try: - response = session.get(api_stock_url, headers=HEADERS, timeout=10) + response = session.get(api_stock_url, timeout=10) logging.info(f"[{product_name}] Stock API response: {response.status_code}") response.raise_for_status() stock_data = response.json()