File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515from ..prints .motor_prints import _MotorPrints
1616from ..tools import parallel_axis_theorem_from_com , tuple_handler
1717
18-
1918# pylint: disable=too-many-public-methods
19+ # ThrustCurve API cache
20+ _thrustcurve_cache = {}
21+
22+
2023class Motor (ABC ):
2124 """Abstract class to specify characteristics and useful operations for
2225 motors. Cannot be instantiated.
@@ -1941,8 +1944,15 @@ def _call_thrustcurve_api(name: str):
19411944 If no motor is found or if the downloaded .eng data is missing.
19421945 requests.exceptions.RequestException
19431946 If a network or HTTP error occurs during the API call.
1947+ Notes
1948+ -----
1949+ - The cache prevents multiple network requests for the same motor name.
1950+ - The returned data is ready to be decoded and loaded via `GenericMotor.load_from_eng_file`.
19441951 """
1952+
19451953 base_url = "https://www.thrustcurve.org/api/v1"
1954+ if name in _thrustcurve_cache :
1955+ return _thrustcurve_cache [name ]
19461956
19471957 # Step 1. Search motor
19481958 response = requests .get (f"{ base_url } /search.json" , params = {"commonName" : name })
@@ -1979,6 +1989,7 @@ def _call_thrustcurve_api(name: str):
19791989 raise ValueError (
19801990 f"Downloaded .eng data for motor '{ name } ' is empty or invalid."
19811991 )
1992+ _thrustcurve_cache [name ] = data_base64
19821993 return data_base64
19831994
19841995 @staticmethod
You can’t perform that action at this time.
0 commit comments