-
Notifications
You must be signed in to change notification settings - Fork 0
feat: caching of map and image tiles #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
LINT build is failing because the pre-commit hasn't been updated to only run on files changed as part of the PR. @jtblack-aws already made those changes as part of PR #73 . |
drduhe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - one comment
| output_size=(tile_size, tile_size), | ||
| ) | ||
| return Response(content=bytes(image_bytes), media_type=get_media_type(tile_format), status_code=status.HTTP_200_OK) | ||
| headers = {"Cache-Control": "private, max-age=604800"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this max age be something we want set as a configuration variable somewhere??
batzela
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ship it
| """ | ||
| cached_tile_count_env = "TILE_PROVIDER_CACHED_TILE_COUNT" | ||
| cached_tile_count_default = 400 | ||
| cached_tile_count = os.getenv(cached_tile_count_env) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the past we've been handling reading env vars in app_config.py and then importing the values from there.
drduhe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
drduhe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs unit tests passing
This PR updates the tile server to cache previously created map and image tiles. It also adds a Cache-Control header that instructs clients to keep the tiles for up to 7 days. Combined these two features eliminate many duplicate tile generation requests improving the overall responsiveness of visualization tools using the tile server.
The implementation introduces a new
TileProviderservice that is injected into the handlers for various tile / map routes. Theget_image_tileandget_map_tilemethods are wrapped in a LRU cache with a max size that can be configured by setting theTILE_PROVIDER_CACHED_TILE_COUNTenvironment variable. This configuration setting defaults to 400 tiles if not found in the environment.Unit tests were updated to validate the new TileProvider and end-to-end functionality was checked through an integration with STACBrowser.
This PR also contains a second commit for a small build issue found during testing. The autopep8 checks run in our pre-commit setup were failing because they could not find the lib2to3 module. That module was officially deprecated / removed in Python 3.11 but older versions of the autopep8 tool still depended on it. Updating to the latest version resolved the issue.
Checklist
Before you submit a pull request, please make sure you have the following:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.