Skip to content

feat: implement simulation cache and integrate with poller module#363

Merged
ayomideadeniran merged 2 commits intoSoroLabs:mainfrom
Dubemtopsite:build-task-execution-252
Apr 30, 2026
Merged

feat: implement simulation cache and integrate with poller module#363
ayomideadeniran merged 2 commits intoSoroLabs:mainfrom
Dubemtopsite:build-task-execution-252

Conversation

@Dubemtopsite
Copy link
Copy Markdown
Contributor

Closes #252

Summary

Implement a short-lived cache for task eligibility simulation results to avoid redundant RPC calls when polling for due tasks.

Changes

New

  • src/simulationCache.js: TTL-based cache with configurable expiration (default 30s), max size limits, and hit/miss statistics

Modified

  • src/poller.js: Integrated simulation cache in checkTask() - checks cache first before RPC call
  • index.js: Cache invalidation on task execution (success/failure) to ensure fresh data after last_run changes

Config

  • .env.example: Added SIMULATION_CACHE_TTL and SIMULATION_CACHE_MAX_SIZE

Why

Task eligibility checks (getTaskConfig) use simulateTransaction via RPC which is expensive. When polling multiple tasks frequently, the same task gets queried repeatedly within seconds. This cache avoids redundant RPC calls while ensuring correctness.

Cache Invalidation Rules

  1. TTL expiration (default 30s) - stale results auto-expire
  2. Explicit invalidation - cache invalidated when task executes (since last_run changes)
  3. Manual - poller.invalidateCache(taskId)
  4. Size limit - LRU eviction when at max capacity

Metrics

poller.getCacheStats()
// { size, hits, misses, hitRatePercent, ttlSeconds }
Testing
- Added __tests__/simulationCache.test.js with coverage for:
  - Basic get/set
  - TTL expiration
  - Single/bulk invalidation
  - Hit rate tracking
  - Cache size limits

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Apr 29, 2026

@Dubemtopsite Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@ayomideadeniran
Copy link
Copy Markdown
Contributor

pr under review, if i find any wrong implementation i will notify you.

@ayomideadeniran ayomideadeniran merged commit eecae84 into SoroLabs:main Apr 30, 2026
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.

[Backend] Build Task Execution Simulation Cache for Repeated Eligibility Checks

2 participants