Skip to content

build_parameters.py: use local cache and server cache to get files#7681

Open
khancyr wants to merge 1 commit intoArduPilot:masterfrom
khancyr:build_parameters_cache
Open

build_parameters.py: use local cache and server cache to get files#7681
khancyr wants to merge 1 commit intoArduPilot:masterfrom
khancyr:build_parameters_cache

Conversation

@khancyr
Copy link
Copy Markdown
Contributor

@khancyr khancyr commented Apr 21, 2026

add local cache as parameters files don't change often
use HEAD request before getting the file to know if it changed or not.

Cache work in 3 steps:

  • Uses cached content if the file is still fresh (ie < 6h)
  • ask the server about the file Last-Modified, if it match cache, use cache
  • if cache cannot be used, get the file from the server.

6h time is totally arbitrary. As we don't update often parameter that look sane to test on 4 time per day and reduce lot the request on the server !
We could work on clever way later for old parameters and perhaps reporting if a modification is noted on old files

image

From testing our server don't return http 304

Copy link
Copy Markdown
Contributor

@peterbarker peterbarker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if this was all tied up in a little object rather than being a bunch of methods, but I'm not going to insist.

Comment thread build_parameters.py Outdated

# Get the directory where this script is located
script_dir = os.path.dirname(os.path.abspath(__file__))
default_cache_dir = os.path.join(script_dir, '.cache')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a bit generic a name

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default_http_request_cache_dir ok ?

Comment thread build_parameters.py Outdated
os.makedirs(cache_dir, exist_ok=True)

# Create cache filename from URL
cache_filename = re.sub(r'[^\w\-_.]', '_', url) + '.cache'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the wrong sort of regex to use here. You should be choosing which characters to keep, not which ones to throw away.

urllib has a quote method available.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about urllib.quote, using it instead of the regex

Comment thread build_parameters.py Outdated
response = session.get(firmware_url + vehicle, timeout=30)
response.raise_for_status()
content = response.text
content = get_cached_url(firmware_url + vehicle)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not what this really does.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, corrected

@khancyr khancyr force-pushed the build_parameters_cache branch 2 times, most recently from 72882ab to 7e08525 Compare April 21, 2026 14:22
@khancyr
Copy link
Copy Markdown
Contributor Author

khancyr commented Apr 21, 2026

@peterbarker comments addressed !

@khancyr khancyr force-pushed the build_parameters_cache branch from 7e08525 to 91076cd Compare April 21, 2026 14:35
@khancyr
Copy link
Copy Markdown
Contributor Author

khancyr commented Apr 21, 2026

@peterbarker , when cache is done in build_parameters.py and update.py, I will consolidate both script with a common lib (logging, http and git things) that will make things easier at a central place

@khancyr khancyr force-pushed the build_parameters_cache branch 2 times, most recently from 99af786 to 678f075 Compare April 22, 2026 08:13
@khancyr khancyr force-pushed the build_parameters_cache branch from 678f075 to e0debf1 Compare April 22, 2026 10:01
@khancyr khancyr requested a review from peterbarker April 22, 2026 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants