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

Implement updated LazyOption type #439

Closed
austinabell opened this issue Jun 11, 2021 · 1 comment
Closed

Implement updated LazyOption type #439

austinabell opened this issue Jun 11, 2021 · 1 comment
Assignees
Labels
good first issue Good for newcomers

Comments

@austinabell
Copy link
Contributor

austinabell commented Jun 11, 2021

Currently, the LazyOption type lives within collections and just behaves as a wrapper around accessing a key/value pair in storage. The benefit to updating this API to have a caching layer in-between is that on multiple gets or sets, the storage does not need to be read and written to multiple times, and only needs to be updated once the variable is dropped out of scope.

Reference for what this API would look like can be seen in #409 where the Lazy type is implemented.

For comparison, both Lazy<T> and LazyOption<T> represent values lazily loaded from storage, where the following should be assumed and have as close of an API as possible:

Lazy -> T
LazyOption -> Option<T>

The difference is just that Lazy assumes the value at the key is always set, where LazyOption behaves like an option where the value can be None.

The criteria of this issue will be as follows:

  • This new data structure will live under the store module, along with Lazy
    • The old API should not be removed yet, as we want to migrate over without breaking changes and not enforce people to use the unstable feature which the near_sdk::store module is under
  • This type should be able to Deref (and DerefMut) into an Option<T> which will load the value from storage, and allow all APIs from Option to become available
    • The API on the structure itself can probably mimic the Lazy type very closely
  • During the lifetime of the variable, storage should only be read max once and written to once.
    • The only exception should be if the flush method is exposed and called to update the storage early, to get storage changes, but the updated value should be kept in the cache so will still never read more than once.
@ChaoticTempest
Copy link
Member

Closed with #444

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants