Skip to content

Conversation

@edparris
Copy link
Contributor

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 TileProvider service that is injected into the handlers for various tile / map routes. The get_image_tile and get_map_tile methods are wrapped in a LRU cache with a max size that can be configured by setting the TILE_PROVIDER_CACHED_TILE_COUNT environment 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:

  • Code changes are compact and well-structured to facilitate easy review
  • Changes are documented in the README.md and other relevant documentation pages
  • PR title and description accurately reflect the changes and are detailed enough for historical tracking
  • PR contains tests that cover all new code and the code has been manual tested
  • All new dependencies are declared (if any), and no unnecessary libraries are added
  • Performance impacts (if any) of the changes are evaluated and documented
  • Security implications of the changes (if any) are reviewed and addressed
  • I have read the Contributing Guidelines and agree to follow the Code of Conduct

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@edparris
Copy link
Contributor Author

edparris commented Mar 28, 2025

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 .

Copy link
Collaborator

@drduhe drduhe left a 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"}
Copy link
Collaborator

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??

Copy link

@batzela batzela left a 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)
Copy link
Contributor

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.

Copy link
Collaborator

@drduhe drduhe left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Collaborator

@drduhe drduhe left a 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants