From 32fd6158ecf8d086ad5d11aa1e87ceb6ff34873f Mon Sep 17 00:00:00 2001 From: monosans Date: Sun, 18 Feb 2024 12:11:04 +0300 Subject: [PATCH] Remove ETag from cache if response didn't provide it --- proxy_scraper_checker/geodb.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/proxy_scraper_checker/geodb.py b/proxy_scraper_checker/geodb.py index ca3864d..c5c18c0 100644 --- a/proxy_scraper_checker/geodb.py +++ b/proxy_scraper_checker/geodb.py @@ -1,5 +1,6 @@ from __future__ import annotations +import asyncio import logging import stat from typing import Optional @@ -28,6 +29,10 @@ async def _read_etag() -> Optional[str]: return bytes_decode(content) +def _remove_etag() -> asyncio.Future[None]: + return asyncify(GEODB_ETAG_PATH.unlink)(missing_ok=True) + + async def _save_etag(etag: str, /) -> None: await fs.async_add_permission( GEODB_ETAG_PATH, stat.S_IWUSR, missing_ok=True @@ -85,3 +90,5 @@ async def download_geodb(*, progress: Progress, session: ClientSession) -> None: if etag := response.headers.get(hdrs.ETAG): await _save_etag(etag) + else: + await _remove_etag()