xBlockOrigin implements a persistent TTL-based cache to minimize API requests and improve performance when browsing X.com.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/chefnaphtha/xBlockOrigin/llms.txt
Use this file to discover all available pages before exploring further.
Cache implementation
The cache is implemented inUtils/cache.ts using chrome.storage.local for persistence across browser sessions.
Cache entry structure
- value - The cached data (string or boolean)
- expiresAt - Expiration timestamp (when entry becomes invalid)
The cache uses lazy cleanup: expired entries are deleted only when accessed, not on a background schedule.
Cache instances
Three global cache instances are created with different TTL values:Country cache
TTL: 24 hours (86,400,000 milliseconds) Storage key pattern:cache:country:{username}
Value type: string (country name)
Purpose: Caches user country detection results from AboutAccountQuery API
Example:
User ID cache
TTL: 24 hours (86,400,000 milliseconds) Storage key pattern:cache:user:{username}
Value type: string (numeric user ID)
Purpose: Caches username-to-userId mapping from UserByScreenName API
Example:
Following cache
TTL: 5 minutes (300,000 milliseconds) Storage key pattern:cache:following:{userId}
Value type: boolean (whether you follow this user)
Purpose: Caches following status from UserByScreenName API (shorter TTL since it changes more frequently)
Example:
Cache API
ThecreateCache<T>(prefix, ttl) factory function creates cache instances with these methods:
get(key: string)
Retrieves a value from cache. Returns:Promise<T | null>
- Returns cached value if present and not expired
- Returns
nullif key doesn’t exist or entry is expired - Automatically deletes expired entries (lazy cleanup)
set(key: string, value: T)
Stores a value in cache with TTL. Returns:Promise<void>
Behavior:
- Calculates
expiresAt = Date.now() + ttl - Stores
{ value, expiresAt }inchrome.storage.local - Overwrites existing entries
has(key: string)
Checks if a key exists in cache and is not expired. Returns:Promise<boolean>
Behavior:
- Returns
trueif key exists and not expired - Returns
falseif key doesn’t exist or is expired - Automatically deletes expired entries (lazy cleanup)
clear()
Deletes all cache entries for this cache instance. Returns:Promise<void>
Behavior:
- Fetches all keys from
chrome.storage.local - Removes all keys matching the cache prefix
- Does not affect other cache instances or storage data
Cache flow in orchestrator
The orchestrator uses a multi-level cache check strategy:This strategy minimizes API calls while ensuring following status is checked more frequently (every 5 minutes) than user IDs and countries (every 24 hours).
Cache invalidation
Cache entries are invalidated in two ways:Time-based expiration (TTL)
Entries automatically expire after their TTL:| Cache Type | TTL | Reason |
|---|---|---|
| Country | 24h | X.com updates country every 30 days |
| User ID | 24h | User IDs never change (username might) |
| Following | 5m | Following status changes frequently |
Manual clearing
The extension does not currently implement manual cache clearing in the UI, but developers can clear cache programmatically:Performance impact
Cache hit rates significantly reduce API requests: Without cache:- 3 API calls per user (UserByScreenName, AboutAccountQuery, CreateMute)
- 100 users = 300 API requests
- 0-1 API calls per user (only CreateMute for new blacklisted users)
- 100 users = 0-100 API requests (depends on how many are blacklisted)
The cache is especially effective when browsing the same pages repeatedly or when users appear multiple times across different pages.
Storage considerations
Cache storage grows over time as more users are encountered: Estimated size per user:- Country cache: ~150 bytes per entry
- User ID cache: ~120 bytes per entry
- Following cache: ~100 bytes per entry
- Total: ~370 bytes per user
- 1,000 users cached: ~370 KB
- 10,000 users cached: ~3.7 MB
- 25,000 users cached: ~9.25 MB (approaching 10MB limit)
chrome.storage.local quota, consider:
- Implementing periodic background cleanup of expired entries
- Adding cache size limits with LRU eviction
- Providing UI option to clear cache