Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
hello world AOP cache aspect
class CacheAspect {
...
@beforeMethod({
methodNamePattern: /^get.*/,
classNamePattern: /^[Book|User]Collection$/
})
beforeGet(meta, args) {
let key = `${meta.name}:${args.join()}`;
let method = meta.method;
method.proceed = true;
if (this.cache.hasOwnProperty(key)) {
method.result = this.cache[key];
method.proceed = false;
}
}
...
}
@Wove
class BookCollection {
...
getNameByISBN(id, article) {
return this.get({
isbn: isbn
}, {
onSuccess: 'name'
onFail: null
});
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment