Skip to content

Instantly share code, notes, and snippets.

@jkantr
Forked from hmpmarketing/remember.js
Last active January 5, 2018 19:10
Show Gist options
  • Save jkantr/f05bd08f8cc00b0ad4867d5bae5916d8 to your computer and use it in GitHub Desktop.
Save jkantr/f05bd08f8cc00b0ad4867d5bae5916d8 to your computer and use it in GitHub Desktop.
Cache.remember = function (key, lifetime, callback) {
return Promise.try(() => {
return memcached.getAsync(key);
}).then((value) => {
if (value !== undefined) {
return value;
} else {
return Promise.try(() => {
return callback()
}).then((value) => {
return memcached.setAsync(key, value, lifetime);
}).then(() => {
return value;
})
}
})
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment