-
Notifications
You must be signed in to change notification settings - Fork 0
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
add cache clearing and testing #10
Changes from 1 commit
3cead0e
35bf869
f7683c4
7aa2393
af47290
3519861
b342c84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from imf_reader.sdr.read_announcements import ( | ||
get_holdings_and_allocations_data, | ||
get_latest_date, | ||
) | ||
from imf_reader.sdr.read_exchange_rate import fetch_exchange_rates | ||
from imf_reader.sdr.read_interest_rate import fetch_interest_rates | ||
from imf_reader.config import logger | ||
|
||
|
||
def clear_cache(): | ||
"""Clear the cache for all lru_cache-decorated functions.""" | ||
|
||
cleared_caches = 0 | ||
|
||
# read_announcements | ||
if ( | ||
get_holdings_and_allocations_data.cache_info().currsize > 0 | ||
or get_latest_date.cache_info().currsize > 0 | ||
): | ||
get_holdings_and_allocations_data.cache_clear() | ||
get_latest_date.cache_clear() | ||
cleared_caches += 1 | ||
logger.info("Cache cleared - Holdings and allocations") | ||
|
||
# read_exchange_rate | ||
if fetch_exchange_rates.cache_info().currsize > 0: | ||
fetch_exchange_rates.cache_clear() | ||
cleared_caches += 1 | ||
logger.info("Cache cleared - Exchange rates") | ||
|
||
# read_interest_rate | ||
if fetch_interest_rates.cache_info().currsize > 0: | ||
fetch_interest_rates.cache_clear() | ||
cleared_caches += 1 | ||
logger.info("Cache cleared - Interest rates") | ||
|
||
if cleared_caches == 0: | ||
|
||
logger.info("Unable to clear cache - No cached data") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might not be a useful message for the user who doesn't necessarily need to know if there is/isn't cached data There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may be misleading to a user as they might think there is an issue with the function call |
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.
cache_clear
should function normally even if there is no cached data, so the condition check and counter might be redundant