Skip to content

Instantly share code, notes, and snippets.

@dns2utf8
Created December 14, 2015 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dns2utf8/d1db02cd530bd809371b to your computer and use it in GitHub Desktop.
Save dns2utf8/d1db02cd530bd809371b to your computer and use it in GitHub Desktop.
use std::time::Duration;
struct CachedValue<T, U> {
last : Duration,
value : T,
updateFunction : U,
}
impl <T, U> CachedValue<T,U> {
pub fn new(base :T, updateFunction :U, duration :Duration) -> CachedValue<T,U> {
CachedValue {
value: base,
last: duration,
updateFunction: updateFunction,
}
}
pub fn value(&self) -> T {
// if timeout Reached
// updateFunction()
self.value
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment