Skip to content

Cache-first strategy in AlphaVantageService to avoid redundant API calls#60

Merged
lukepring merged 2 commits intoSprint-2-Jackfrom
copilot/sub-pr-55-one-more-time
Mar 20, 2026
Merged

Cache-first strategy in AlphaVantageService to avoid redundant API calls#60
lukepring merged 2 commits intoSprint-2-Jackfrom
copilot/sub-pr-55-one-more-time

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 20, 2026

fetchSharePrices() always hit the Alpha Vantage API first, treating the repository purely as an error fallback — meaning every call incurred HTTP latency and counted against rate limits even for previously fetched data.

Changes

  • Cache-first lookup: fetchSharePrices() now queries the repository before making any HTTP request. A cache hit returns immediately; the API is only called on a cache miss.
List<PriceData> cached = repository.loadPrices(symbol, startDate, endDate);
if (!cached.isEmpty()) {
    log.debug("Returning cached prices for symbol={} ({} to {})", symbol, startDate, endDate);
    return cached;
}
// only reaches Alpha Vantage if cache is empty
String json = fetchTimeSeriesDailyJson(symbol, outputSize);

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: lukepring <68820847+lukepring@users.noreply.github.com>
Copilot AI changed the title [WIP] [WIP] Address feedback from review on Sprint 2 jack pull request Cache-first strategy in AlphaVantageService to avoid redundant API calls Mar 20, 2026
Copilot AI requested a review from lukepring March 20, 2026 15:54
@lukepring lukepring marked this pull request as ready for review March 20, 2026 15:57
@lukepring lukepring merged commit ae829e6 into Sprint-2-Jack Mar 20, 2026
@lukepring lukepring deleted the copilot/sub-pr-55-one-more-time branch March 20, 2026 15:58
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.

2 participants