feat: In-memory TTL cache to reduce API calls by 50-90%#19
Open
romancircus wants to merge 1 commit intotacticlaunch:mainfrom
Open
feat: In-memory TTL cache to reduce API calls by 50-90%#19romancircus wants to merge 1 commit intotacticlaunch:mainfrom
romancircus wants to merge 1 commit intotacticlaunch:mainfrom
Conversation
The Linear SDK eagerly resolves all relationships for each entity, causing N+1 query patterns. For example, getIssues(25) makes ~151 API calls (1 list + 25 * 6 relationship fetches). This quickly exhausts Linear's 5,000 requests/hour rate limit when used with AI coding assistants that make frequent read calls. This adds a transparent caching layer with: - Per-resource TTLs (teams: 1hr, issues: 2min, search: 1min) - LRU eviction when cache reaches max size (default: 500) - Automatic invalidation on write operations - Two new MCP tools: linear_cacheStats and linear_clearCache - Opt-out via LINEAR_CACHE_ENABLED=false env var - Configurable max size via LINEAR_CACHE_MAX_SIZE env var - Zero new dependencies (pure Map-based implementation) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Member
|
@romancircus sounds fair, but you need to add information about the new ENV and TTL to the README |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
LinearService, reducing redundant Linear API calls by 50-90%getIssues(25)makes ~151 API callsWhat's Included
src/services/cache.tssrc/services/cached-linear-service.tsLinearService— caches all reads, invalidates on writessrc/tools/definitions/cache-tools.tslinear_cacheStatsandlinear_clearCacheMCP tool definitionssrc/tools/handlers/cache-handlers.tssrc/index.tsCachedLinearService(opt-out via env var)Design Decisions
LINEAR_CACHE_ENABLED=falseMap-based implementationCachedLinearService extends LinearService, same API surfaceLINEAR_CACHE_MAX_SIZE) with LRU evictionTTL Configuration
Test plan
tsc --noEmitpasses with zero errorstsc) succeeds🤖 Generated with Claude Code