Skip to content

Implement composite cache#765

Open
mxiao-cll wants to merge 3 commits intomainfrom
OPDATA-6402
Open

Implement composite cache#765
mxiao-cll wants to merge 3 commits intomainfrom
OPDATA-6402

Conversation

@mxiao-cll
Copy link
Copy Markdown
Contributor

@mxiao-cll mxiao-cll commented May 7, 2026

Background: https://smartcontract-it.atlassian.net/browse/OPDATA-6402

Commit 1:

  • Split ResponseCache into ResponseCache (base) and SimpleResponseCache (implementation)
  • Move constructor into base
  • Move writeTTL into base
  • Move cache entry creation logic into base
  • Everything else is in implementation

Commit 2:

  • Re-structure cache so that we can use different transport name for cache key & meta in EA response field
    • If we have a composite transport holding http and ws transport, we still want http and ws transport to write into the same cache key, however the EA response should reflect which transport is used to generate this answer
  • Implement compare cache
    • It holds a responseCache which actually writes into cache
    • It also takes a shouldUpdate function to determine if new entry should be written into cache or not
    • Instead of always loading from cache, it maintains a list of recently written entry so we do a local comparison first
    • It uses responseCache's transport for cache key but it's own transport for EA response meta
  • Implement composite transport
    • Initialize all the child transport with the same compare cache
    • Simply forward each operation to the individual child transport and let cache do the work

Commit 3:

  • Add docs

How to use this: https://github.com/smartcontractkit/external-adapters-js/pull/4939/changes

@mxiao-cll mxiao-cll requested a review from a team as a code owner May 7, 2026 23:34
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

👋 mxiao-cll, thanks for creating this pull request!

To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team.

Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks!

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

NPM Publishing labels 🏷️

🟢 This PR has valid version labels and will cause a patch bump.

Copy link
Copy Markdown
Contributor

@alejoberardino alejoberardino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mxiao-cll from the ticket for this change I agree with your challenge arguments wholeheartedly, would be good to see the intended effect of this change in the concrete impl you have in mind even as a draft

@mxiao-cll mxiao-cll requested a review from alejoberardino May 8, 2026 03:32
@mxiao-cll
Copy link
Copy Markdown
Contributor Author

mxiao-cll commented May 8, 2026

@mxiao-cll from the ticket for this change I agree with your challenge arguments wholeheartedly, would be good to see the intended effect of this change in the concrete impl you have in mind even as a draft

Big PR here you go and example usage here: https://github.com/smartcontractkit/external-adapters-js/pull/4939/changes

@mxiao-cll mxiao-cll force-pushed the OPDATA-6402 branch 2 times, most recently from ca83238 to a414c9e Compare May 8, 2026 13:12
@mxiao-cll mxiao-cll changed the title Create a base class for response cache Implement composite cache May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants