question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

change default cache resolver

See original GitHub issue

the default cache resolver simply does a JSON.stringify test against the old and new parameters. This does not take into account the position of the properties and can lead to false results (depending on your point of view).

If you were to use object-hash to compare the two objects this is no longer an issue. See the code sample below

const hash = require('object-hash');

const p1 = { d1: 'd1', d2: 'd2' };
const p2 = { d2: 'd2', d1: 'd1' };

const hash1 = hash(p1);
const hash2 = hash(p2);

console.log('json', JSON.stringify(p1) === JSON.stringify(p2));
console.log('hash', hash1, hash2, hash1 === hash2);

the result of this is

json false hash f4c434a0e4c11deb776f4281c9b3848ccbe63578 f4c434a0e4c11deb776f4281c9b3848ccbe63578 true

this could be implemented by default , or by adding an option to specify a different cache resolver so that it won’t break existing code that relies on key position creating different cache results

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
angelnikolovcommented, Sep 27, 2018

Let me think about that… That’s quite a jump for a 6kb library. It drags along crypto which is pretty big. I feel like the benefit we gain from adding this compare to what we lose is smaller and is something that can be mitigated by a better documentation, i.e - if you want your cache to resolved properly for object parameters, they should have the same shape.

0reactions
Ayushidawadacommented, Aug 25, 2020

@angelnikolov Can you please give me an example of using cacheResolver and cacheHasher and its difference,As i am using your package for my project,as of now not facing any issue while using other configurations except this two.

Read more comments on GitHub >

github_iconTop Results From Across the Web

change default cache resolver · Issue #14 - GitHub
There is an option to specify a different cache resolver already. You can just supply a cacheResolver to the config. All reactions.
Read more >
33. Caching - Spring
Some offer a way to customize the default caches defined by the ... It is also possible to force a particular cache provider...
Read more >
3 Ways to Configure Multiple Cache Managers in Spring Boot
We can define a default cache manager using this approach. You can continue using the caching annotation with no change.
Read more >
spring cache with custom cacheResolver - Stack Overflow
Plain caching config works. I've lookad at spring code, it reads cacheResolver correctly but then fails on validation. Looks like a Spring bug ......
Read more >
The default resolver settings - IBM
The following resolver functions are active by default: System-wide caching, which uses the default maximum cache size, the default maximum time-to-live (TTL) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found