Skip to content
New issue

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

Allow prevention of caching "null" strings/objects #35

Closed
mrnohr opened this issue May 28, 2014 · 1 comment
Closed

Allow prevention of caching "null" strings/objects #35

mrnohr opened this issue May 28, 2014 · 1 comment

Comments

@mrnohr
Copy link

mrnohr commented May 28, 2014

Currently, if I use the redisService.memoize() or @memoize annotation, it will store the result in redis even if the value is null. There are cases where I do not want to cache null values.

For example, if I'm using @MemoizeDomainObject on a find method like this:

@MemoizeDomainObject(key = "#{title}", clazz = Book.class)
def findBookByTitle(String title){
    def book = // some expensive find operation
    return book
}

I only want to cache this if a book is found. If not found (and null is returned), then I always want to look up the value again in case the book was added. I am actually more interested in the @MemoizeObject annotation, but it would apply to @MemoizeDomainObject as well.

I was thinking some kind of flag on the annotation.

For now when I want this behavior, I use the annotation(s) and then delete the redis key if null is returned. This is 3 redis calls (GET to check the key, SETEX to add null, then DEL to remove it) when I'd rather have 1 redis call (GET) in this case.

tednaleid added a commit that referenced this issue May 29, 2014
add `cacheNull: false`  option to `memoizeObject`, fixes #35
@tednaleid
Copy link
Contributor

I added this to the new memoizeObject method (that I implemented for #34). It's not currently on all of the annotations as I'm not sure quite how much this will get used, but could see some use-cases for it and it was easy enough to put on the new method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants