-
-
Notifications
You must be signed in to change notification settings - Fork 588
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
Unable to cache a value of null #824
Comments
Could you create a PR? I think we can avoid the breaking change if we switch the old/new logic with a cacher option, e.g. |
By the way, as I see, the value is stored, just not return it, right? |
Yes, from what I noticed, the value is properly stored and retrieved but the code I highlighted makes it seem like a cache miss and calls the action anyway. Regarding the PR, I could do it if we come up with a good non-breaking solution, yes. I thought it could be regarded as a breaking change for people who use custom cachers but I guess the configuration option fixes this issue. |
Yeah, but in this case, the option name |
Thanks for your answer. To make sure I understand:
Is this correct? |
Yeah, you are correct. Could you make a PR? Of course, need to add relevant tests, as well. |
@Telokis any news? |
@Telokis thanks for the answer. I have now submitted for consideration changes to the serialization algorithm in order to solve 3 urgent problems at once, including yours. |
@intech Ok, seems like a good idea, thank you for letting me know about it! |
I've added a |
Prerequisites
Please answer the following questions for yourself before submitting an issue.
Current Behavior
null
andundefined
cannot be cached by moleculer.Expected Behavior
I expected at least
null
to be a cacheable value.Failure Information
More often than not, a specific action will be invalid. For example, trying to get a specific id from database but it doesn't exist.
In such a case, it makes sense to return
null
but I don't want to be flooded by requests since I know it won't return anything other thannull
until I ask the cache to be cleaned.Steps to Reproduce
null
.Reproduce code snippet
Possible solution
Instead of using a weak comparison against
null
in the cacher base (cachers/base.js#L303) we can strongly compare againstundefined
using!== undefined
.But I think the best solution would be to use a
Symbol
which is specific to moleculer. This way, we know nobody will be tempted to return it from inside their action.However, I understand that this would be a breaking change (and I'm a bit saddened by this fact).
The text was updated successfully, but these errors were encountered: