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

Takes long time to cache (set&get) large JSON objects #295

Open
alexatbam opened this issue Sep 21, 2022 · 2 comments
Open

Takes long time to cache (set&get) large JSON objects #295

alexatbam opened this issue Sep 21, 2022 · 2 comments

Comments

@alexatbam
Copy link

I have noticed that it takes really long time when i add and retrieve data that is a json array (25k elements).
If I stringily the obj its 10x faster.

any recommendation instead of stringily and then parse?

"node-cache": "^5.1.2"
node ver : v16.14.2
thanks

@LiveGood
Copy link

LiveGood commented Nov 2, 2022

When creating an instance of the cache this should help:
myCache.options.useClones = false;

By default node-cache creates deep clones of each object you set, so a large object will take much longer to be deep cloned than a large string.
Take in mind that if you set this option to false, if for some reason you need to store the same object twice under different keys, both objects will have the same reference, and change in one will affect the other.
You can avoid this by doing the deep cloning yourself when needed.

@matys1
Copy link

matys1 commented Jan 24, 2023

@LiveGood thanks, this helped with my issue. Was querying 125k rows over 4 columns and it would take 11s to return from cache (slower than if I would query API directly). After turning this to false it's getting it from cache in <500ms.

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

3 participants