We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
obtain
getOrCreate
With nullability this would likely be useful. Also sometimes you want to force creation and not get a cached value.
We could make it an extension or a new method on Entry.
Entry
extension NeatCacheEntry<T> on Entry<T> { // Get or create a value. Future<T> obtain( Future<T> Function() create, { Duration? ttl, bool purgeCache = false, }) async { if (purgeCache) { final value = create(); if (ttl != null) { await set(value, ttl); } else { await set(value); } return value; } if (ttl != null) { return (await get(create, ttl))!; } return (await get(create))!; } }
The text was updated successfully, but these errors were encountered:
Fair question is if create should be allowed to return null.
create
null
Sorry, something went wrong.
No branches or pull requests
With nullability this would likely be useful. Also sometimes you want to force creation and not get a cached value.
We could make it an extension or a new method on
Entry
.The text was updated successfully, but these errors were encountered: