Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: use KV to cache values #42

Open
whoabuddy opened this issue Mar 4, 2022 · 0 comments
Open

Feature: use KV to cache values #42

whoabuddy opened this issue Mar 4, 2022 · 0 comments

Comments

@whoabuddy
Copy link
Contributor

While caching isn't generally recommended in an API, there are values that do not need to be fetched multiple times as they are written into the chain history.

With that in mind, there are a few strategies that could be deployed here, and Workers KV should be a great match for the task. It supports very high read volumes and would reduce load on the main API.

The KV objects could be named in the format: {city}-{datapoint}, e.g.

  • mia-activationblock
  • mia-miningstatsatblock
  • mia-stackingstatsatcycle
  • mia-totalsupply

The naming should be in alignment with the contract variable/map/function names, types directory, and handlers so it's easily associated. City data can be filtered by the city abbreviation when fetching a full list of keys.

Data points like mia-activationblock can be queried if not found per city, then stored indefinitely and used to serve the response.

Data points like mia-totalsupply could take advantage of expiring keys to make sure the data gets fetched again in regular intervals.

Data could be updated as it's fetched, or a cron job could be run by the worker to make updates on regular intervals, or both.

Additional general KV data points could be used as well, such as saving the last seen block height and using that to determine if a new value needs to be fetched.

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

No branches or pull requests

1 participant