Skip to content

How to implement caching modifier over ethers v5? #4740

Closed Answered by peersky
peersky asked this question in Q&A
Discussion options

You must be logged in to vote

I ended up wrapping a provider instead.

For anyone who might need same:

const { DefenderRelayProvider } = require('@openzeppelin/defender-sdk-relay-signer-client/lib/ethers');
const { debug } = require('./debug');
/**
 * CachedDefenderProvider extends DefenderRelayProvider and provides caching functionality for contract calls.
 * It utilizes a key-value store client to store and retrieve cached contract data.
 * @class
 * @extends DefenderRelayProvider
 */
class CachedDefenderProvider extends DefenderRelayProvider {
  #cacheNetwork;

  constructor(props, kvsClient) {
    super(props);
    this.#cacheNetwork = props.network;
    this.staleTime = props?.staleTime ?? 388800000; // 45 days
    

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by peersky
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant