Caching a contract query/promise #1442
Unanswered
ethernalquestion
asked this question in
Q&A
Replies: 1 comment 9 replies
-
There are certain queries like Now a quick approach can be to maintain a dictionary of all the cached values. let cache = {};
setInterval(async() => {
const balance = await contract.balanceOf('0xabc...');
const symbol = cache['token-symbol'] !== undefined ? cache['token-symbol'] : (cache['token-symbol'] = await contract.symbol());
}, 5000)
I'm trying to understand this, can you explain this or maybe share a code snippet example? |
Beta Was this translation helpful? Give feedback.
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Searched everywhere but could not find a solution to this. I would like to cache a set of promises that would call contract.function.method, or contract.staticCall.method. My problem is that I am basically repeatedly doing these queries and I want to remove the overhead of building the promise every block. Is there a way to do this currently?
The closest I could get was to cache the queries for several different blockTags in the future, but unfortunately it seems like the actual query evaluates in the background even though the promise was not called with promise.all yet.
Really appreciate your help, thanks a lot!
Beta Was this translation helpful? Give feedback.
All reactions