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

How about Contains / Exists implementation for a key? #46

Closed
keerthivasanm opened this issue Mar 7, 2016 · 6 comments
Closed

How about Contains / Exists implementation for a key? #46

keerthivasanm opened this issue Mar 7, 2016 · 6 comments

Comments

@keerthivasanm
Copy link

It really helps if the value is a huge payload.

@MichaCo
Copy link
Owner

MichaCo commented Mar 7, 2016

Yup, sounds like a potential improvement

@killergege
Copy link

I'm a bit surprised that this is missing, it's a basic feature for a cache manager !
How do you know that the value returned by Get is a cached value or a default value because the key doesn't exist ?
To me it sounds dangerous to return a value if the key doesn't exist...

@MichaCo
Copy link
Owner

MichaCo commented May 11, 2016

@killergege That's the normal behavior of caches. If the key doesn't exist, you cannot return anything. And CacheManager returns default(TCacheValue) which is null for value types etc...

The only other option would be throwing a not found exception, which would cause all kinds of other oddness because then you'd have to try/catch every cache call... Which is even worse than a null check...

That being said, a TryGet and/or Exists method will be helpful for non value types.
Although, you can always use the GetCacheItem method which will always return null if a key doesn't exist, independent of the TCacheValue

@jzabroski
Copy link

Agreed with MichaC. Null is a meaningless value. If you want a way to reify
a null, create a Maybe wrapper type. There are many projects on github
which provide not only Maybe but Option type as well (to denote optional
parameters/values).
On May 11, 2016 1:08 PM, "MichaC" [email protected] wrote:

@killergege https://github.com/killergege That's the normal behavior of
caches. If the key doesn't exist, you cannot return anything. And
CacheManager returns default(TCacheValue) which is null for value types
etc...

The only other option would be throwing a not found exception, which would
cause all kinds of other oddness because then you'd have to try/catch every
cache call... Which is even worse than a null check...

That being said, a TryGet and/or Exists method will be helpful for non
value types.
Although, you can always use the GetCacheItem method which will always
return null if a key doesn't exist, independent of the TCacheValue


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#46 (comment)

@sam-piper
Copy link

+1 - we would really like this feature too. We have cache loading algorithms that we want to transfer from a previous caching implementation that need to test for the existence of keys without transferring any values from the Redis layer, otherwise performance suffers.

For now I'll have to plug this gap manually, would be great to have official support in the CacheManager API.

@MichaCo MichaCo modified the milestones: Version 1.0, Version 0.9.3 Dec 3, 2016
MichaCo added a commit that referenced this issue Dec 5, 2016
@MichaCo
Copy link
Owner

MichaCo commented Jan 11, 2017

@sam-piper @keerthivasanm
Sorry that it took so long but it's finally implemented and will be in the next release.

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

No branches or pull requests

5 participants