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

Feat/remove serialization #55

Merged
merged 3 commits into from
Oct 29, 2019
Merged

Feat/remove serialization #55

merged 3 commits into from
Oct 29, 2019

Conversation

angelnikolov
Copy link
Owner

@iherwig @SansDK Please check this PR.
It introduces a custom cacheHasher configuration which allows to pass a custom hash function which will be used to calculate the cacheKey for a method call, based on the passed parameters.
The default cache hasher is still using JSON.parse(JSON.stringify(parameters)) but the parameters passed to the original function will no longer be mutated.
Please test it out if you can and let me know if it works for you, it is published in NPM as beta here.

@SansDK
Copy link

SansDK commented Oct 28, 2019

This works for me, thanks a lot!
I now pass a custom cacheHasher to the @Cacheable decorator.

As a complete example, I use it like this:

@Cacheable({
  maxAge: 3600000,
  cacheHasher: (parameters: Array<any>) =>
    parameters.map(param =>
      param !== undefined
        ? JSON.parse(JSON.stringify(param, (key, value) => {
            if (key === '_meta') {return undefined; }
            else {return value; }}))
        : param
    )
})

This way, it ignores the _meta property in the JSON object, which solves my recursive JSON issue.

Is this the correct way to use the new feature in this PR?

@angelnikolov
Copy link
Owner Author

@SansDK, yes this is the correct way :)

@iherwig
Copy link

iherwig commented Oct 28, 2019 via email

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.

3 participants