Skip to content
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

Merged
merged 7 commits into from
Dec 19, 2024
Merged

add cache clearing and testing #10

merged 7 commits into from
Dec 19, 2024

Conversation

mharoruiz
Copy link
Collaborator

Added cache clearing functionality to the following SDR modules:

  • read_announcements.py
  • read_exchange_rate.py
  • read_interest_rate.py

Also updated tests accordingly.

@mharoruiz mharoruiz linked an issue Dec 17, 2024 that may be closed by this pull request
@codecov-commenter
Copy link

codecov-commenter commented Dec 17, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.95%. Comparing base (e060a8f) to head (b342c84).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #10      +/-   ##
==========================================
+ Coverage   93.75%   93.95%   +0.20%     
==========================================
  Files          11       12       +1     
  Lines         320      331      +11     
==========================================
+ Hits          300      311      +11     
  Misses         20       20              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mharoruiz
Copy link
Collaborator Author

FYI @lpicci96

@lpicci96
Copy link
Collaborator

Thanks @mharoruiz

From a user perspective, they would import the sdr module to have access to the function. eg

from imf_reader import sdr

df = sdr.fetch_exchange_rates()

The clear cache should apply to all the sdr functions and called as

sdr.clear_cache()

@mharoruiz
Copy link
Collaborator Author

Good point! @lpicci96

Let me know what you think now.

Copy link
Collaborator

@lpicci96 lpicci96 left a comment

Choose a reason for hiding this comment

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

Thanks @mharoruiz

I think we can simplify the functionality. From a user perspective, it doesn't matter if there is cached data or not. It is only important they know that after calling the function, there is indeed no cached data. Unless you have a strong argument, I would suggest simplifying the function by removing the counter, simplifying the log message, and clearing the cache regardless if there is cached data or not


if cleared_caches == 0:

logger.info("Unable to clear cache - No cached data")
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

or get_latest_date.cache_info().currsize > 0
):
get_holdings_and_allocations_data.cache_clear()
get_latest_date.cache_clear()
Copy link
Collaborator

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


if cleared_caches == 0:

logger.info("Unable to clear cache - No cached data")
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

@@ -54,7 +54,10 @@ def format_date(month: int, year: int) -> str:


@lru_cache
def get_holdings_and_allocations_data(year: int, month: int):
def get_holdings_and_allocations_data(
month: int,
Copy link
Collaborator

Choose a reason for hiding this comment

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

@mharoruiz you accidentally switched the order of these parameters which are causing an issue further down the pipeline. The functionfetch_allocations_holdings fails as a result. The tests are passing though. Please can you check this bug?

The cache clearing functionality looks good though. Once the issue is addressed I can merge

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry about that! I though it would usability but forgot to adjust the references down the line. It should be fixed now.

@lpicci96 lpicci96 merged commit 65adbd2 into main Dec 19, 2024
6 checks passed
@lpicci96 lpicci96 deleted the 9-clear_cache branch December 20, 2024 09:36
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.

clear_cache
3 participants