Clear Cache
Remove cached data, either all of it or only the part you specify.
The Finance Toolkit never clears the cache on its own. A cache can represent a large amount of downloaded data and a meaningful part of an API quota, so discarding it is always an explicit action. Even a change in the cache’s own internal structure only produces a warning pointing at this method rather than removing anything.
Because the cache is stored per source, per dataset and per entity, removal can be narrowed instead of wholesale. Clearing a single stale ticker, or everything retrieved from one provider, leaves the rest of the cache intact.
Clear Cache in Python
clear_cache is part of the Toolkit module of the open-source Finance Toolkit. Install it with:
pip install financetoolkit -U
Then call clear_cache as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(["AAPL", "MSFT"], api_key="FINANCIAL_MODELING_PREP_KEY", use_cached_data=True)
# Remove only the price history of a single ticker
toolkit.clear_cache(source="YahooFinance", ticker="AAPL")
# Remove everything retrieved from the OECD
toolkit.clear_cache(source=policy_model.OECD)
# Remove the entire cache
toolkit.clear_cache(confirm=True)
Parameters
clear_cache accepts the following parameters:
- source (str | None): Only remove data from this source, for example “FinancialModelingPrep”, “YahooFinance”, “OECD”, “FRED” or “GlobalMacroDatabase”. These match the names used by enforce_source. Defaults to None, which matches every source.
- dataset (str | None): Only remove this dataset within the source, for example “historical”, “intraday” or “statements”. Defaults to None, which matches every dataset.
- ticker (str | None): Only remove this entity, for example “AAPL” or a country code for macroeconomic data. Defaults to None, which matches every entity.
- confirm (bool): Required to be True when no source, dataset or ticker is given, since that removes the entire cache. Defaults to False.