-
Notifications
You must be signed in to change notification settings - Fork 254
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
feat(collections): Lazy storage value #409
Conversation
per our discussions, I will be moving this type to the new module. The name is still not specified, so either |
near-sdk/Cargo.toml
Outdated
@@ -29,6 +29,9 @@ near-primitives-core = "=0.4.0" | |||
# Export dependencies for contracts | |||
wee_alloc = { version = "0.4.5", default-features = false, features = [] } | |||
|
|||
# Used for caching, might be worth porting only functionality needed. | |||
once_cell = { version = "1.7.2", optional = true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
once_cell = { version = "1.7.2", optional = true } | |
once_cell = { version = "1.7.2", optional = true, default-features = false } |
I think need only no_std (single threaded ) version.
|
@@ -0,0 +1,91 @@ | |||
use borsh::{BorshDeserialize, BorshSerialize}; | |||
|
|||
use super::Lazy; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
me this weekend.
/// This will only write to the underlying store if the value has changed, and will only read the | ||
/// existing value from storage once. | ||
/// | ||
/// # Examples |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again appreciate these doc examples
As mentioned in #406 this implements the lazy storage type, which is similar to
LazyOption
except that the assertion that the value exists in storage is maintained by the API to allow easier usage for developers.This PR re-uses the cache entry type from #402 (with small adjustments) to solidify that API and ensure it can be used for other types. Also for simplicity, this brings in the
once_cell
crate for lazily filling the cache cell under the feature flag, but only specific logic needed can be ported over to minimize compiled size if necessary.