diff options
author | JordonPhillips <phjordon@amazon.com> | 2017-01-04 17:14:12 -0800 |
---|---|---|
committer | JordonPhillips <phjordon@amazon.com> | 2017-01-04 17:14:12 -0800 |
commit | 751161dbbdc02ce998bbbba8d86d1b0add020a42 (patch) | |
tree | b4063dbcbbd4351645bf39037f37c75238edb571 /boto/regioninfo.py | |
parent | b3b326e9c22ea38e15a6f2d8597c4a76aaaca6a2 (diff) | |
download | boto-751161dbbdc02ce998bbbba8d86d1b0add020a42.tar.gz |
Cache loaded builtin endpoints
Diffstat (limited to 'boto/regioninfo.py')
-rw-r--r-- | boto/regioninfo.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/boto/regioninfo.py b/boto/regioninfo.py index e91bdd6e..c5be33d7 100644 --- a/boto/regioninfo.py +++ b/boto/regioninfo.py @@ -29,6 +29,9 @@ from boto.endpoints import BotoEndpointResolver from boto.endpoints import StaticEndpointBuilder +_endpoints_cache = {} + + def load_endpoint_json(path): """ Loads a given JSON file & returns it. @@ -112,12 +115,23 @@ def load_regions(): return endpoints -def _load_builtin_endpoints(): +def _load_builtin_endpoints(_cache=_endpoints_cache): """Loads the builtin endpoints in the legacy format.""" + # If there's a cached response, return it + if _cache: + return _cache + + # Load the endpoints file endpoints = _load_json_file(boto.ENDPOINTS_PATH) + + # Build the endpoints into the legacy format resolver = BotoEndpointResolver(endpoints) builder = StaticEndpointBuilder(resolver) - return builder.build_static_endpoints() + endpoints = builder.build_static_endpoints() + + # Cache the endpoints and then return them + _cache.update(endpoints) + return _cache def get_regions(service_name, region_cls=None, connection_cls=None): |