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

pass JSON object to redisCacheModule #13

Merged
merged 1 commit into from
Jan 30, 2018
Merged

pass JSON object to redisCacheModule #13

merged 1 commit into from
Jan 30, 2018

Conversation

hugosato
Copy link
Contributor

When caching response containing a data property of type Buffer, the JSON.stringify method will wrap the data property with {type: 'Buffer', data} (See node).

The get from cache module will then parse it back to an generic object instead of a Buffer.

This fix allows the cache user to use a custom parser instead.

@@ -36,7 +36,9 @@ function redisCacheModule(config){
self.backgroundRefreshIntervalCheck = (typeof config.backgroundRefreshIntervalCheck === 'boolean') ? config.backgroundRefreshIntervalCheck : true;
self.backgroundRefreshInterval = config.backgroundRefreshInterval || 60000;
self.backgroundRefreshMinTtl = config.backgroundRefreshMinTtl || 70000;
self.JSON = config.JSON || Object.create(JSON);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this just be self.JSON = config.JSON || JSON;?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can but it’s a bit error prone from what I experienced while writing the respective test case.

That’s because the JSON object is a global object and having redisCacheModule.JSON referencing it can lead to some inadvertent problems, e.g.: infinite recursion if the overrode method calls into the global method.

@jpodwys
Copy link
Owner

jpodwys commented Jan 29, 2018

Thanks for this! It's looking good aside from my note on the PR.

@jpodwys jpodwys merged commit 9f5bc1e into jpodwys:master Jan 30, 2018
@jpodwys
Copy link
Owner

jpodwys commented Jan 30, 2018

Published to NPM as 1.3.0. Thanks again!

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

Successfully merging this pull request may close these issues.

2 participants