Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces a file-based caching mechanism to persist API responses locally, addressing the limitations of in-memory caching. The goal is to reduce redundant API calls and improve data retrieval efficiency, especially after service restarts.
Motivation
Previously, local memory caching was volatile — all cached data was lost after a system restart. This resulted in repeated data retrieval for large financial datasets, increasing both latency and API usage.
The new file cache persistence ensures that frequently accessed data remains available between sessions, significantly improving efficiency.
Key Changes
Implemented file-based caching for financial dataset APIs.
Added cache date comparison logic — the system decides whether to refresh data based on the query date versus the cached date.
Introduced partial data fetching — data is retrieved incrementally, with caching prioritized in later requests to minimize API calls.
Enhanced cache tracking and statistics — cache usage, hit/miss rates, and update frequency are now logged and displayed.
Refactored related functions:
get_financial_metrics
search_line_items
get_insider_trades
get_company_news
These functions now record the latest_cached_date based on query time (if within the same day) instead of data retrieval time, ensuring the cache remains valid for daily queries.
Additional Updates
Added .cache directory and updated .gitignore accordingly.
Improved readability and organization of line-item caching logic.
Standardized all cache-related messages and statistics output to English.
Benefits
Reduced redundant API calls.
Improved response time for frequently queried datasets.
Persistent cache across restarts.
Better observability of caching behavior.