amazing cache #55

Merged
kscheidecker merged 22 commits from backend/grid-based-cache into main 2025-01-30 12:40:36 +00:00
3 changed files with 26 additions and 22 deletions
Showing only changes of commit 699737bc40 - Show all commits

View File

@@ -14,7 +14,7 @@ from .utils.landmarks_manager import LandmarkManager
from .utils.toilets_manager import ToiletsManager
from .optimization.optimizer import Optimizer
from .optimization.refiner import Refiner
from .overpass.overpass import fill_cache
from .overpass.caching_strategy import fill_cache
from .cache import client as cache_client

View File

@@ -3,6 +3,7 @@ import json
import hashlib
from ..constants import OSM_CACHE_DIR, OSM_TYPES
from .overpass import Overpass
def get_cache_key(query: str) -> str:
@@ -133,3 +134,27 @@ class CachingStrategy:
selector: str, conditions: list=None, out='center'):
"""Create a hollow cache entry."""
cls.__strategy.set_hollow(key, cell, osm_types, selector, conditions, out)
def fill_cache():
"""
Scans the specified cache directory for files starting with 'hollow_' and attempts to load
their contents as JSON to fill the cache of the Overpass system.
"""
overpass = Overpass()
with os.scandir(OSM_CACHE_DIR) as it:
for entry in it:
if entry.is_file() and entry.name.startswith('hollow_'):
try :
# Read the whole file content as a string
with open(entry.path, 'r') as f:
# load data and fill the cache with the query and key
json_data = json.load(f)
overpass.fill_cache(json_data)
# Now delete the file as the cache is filled
os.remove(entry.path)
except Exception as exc :
overpass.logger.error(f'An error occured while parsing file {f} as .json file')

View File

@@ -321,24 +321,3 @@ def get_base_info(elem: dict, osm_type: OSM_TYPES, with_name=False) :
return osm_id, coords, name
else :
return osm_id, coords
def fill_cache():
overpass = Overpass()
with os.scandir(OSM_CACHE_DIR) as it:
for entry in it:
if entry.is_file() and entry.name.startswith('hollow_'):
# Read the whole file content as a string
with open(entry.path, 'r') as f:
try :
# load data and fill the cache with the query and key
json_data = json.load(f)
overpass.fill_cache(json_data)
except Exception as exc :
overpass.logger.error(f'An error occured while parsing file {f} as .json file')
# Now delete the file as the cache is filled
os.remove(entry.path)