Skip to content

Instantly share code, notes, and snippets.

@hmpmarketing
Forked from jkantr/remember.js
Created January 5, 2018 19:10
Show Gist options
  • Save hmpmarketing/e2f0d9a31d997b89a52fca685f311780 to your computer and use it in GitHub Desktop.
Save hmpmarketing/e2f0d9a31d997b89a52fca685f311780 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