Gottox / mongoose-cache

Caches Database querys the easy way. This module is currently not developed. Nevertheless, I will apply patches.
MIT License
36 stars 23 forks source link

Circular referencing error in JSON.stringify #2

Closed sumeetattree closed 10 years ago

sumeetattree commented 10 years ago

Enno,

The module throws an error TypeError: Converting circular structure to JSON with mongoose 3.8.0.

https://github.com/Gottox/mongoose-cache/blob/master/lib/cache.js#L55

pablote commented 10 years ago

I got the same error, probably because of the complexity of the query. I tried replacing that line with:

return JSON.stringify(query._conditions);

And it works great. Is there any reason why not only the query object is used as the key? This is the app output, with debug flag enabled, after my change:

save to cache:  {"$or":[{"$and":[{"type":"group"},{"name":{"$in":["Administrator"]}}]},{"$and":[{"type":"user"},{"name":"admin"}]}]}
cache hit:  {"$or":[{"$and":[{"type":"group"},{"name":{"$in":["Administrator"]}}]},{"$and":[{"type":"user"},{"name":"admin"}]}]}
cache hit:  {"$or":[{"$and":[{"type":"group"},{"name":{"$in":["Administrator"]}}]},{"$and":[{"type":"user"},{"name":"admin"}]}]}
Gottox commented 10 years ago

I'll change that. Thanks for the fix :)

kimar commented 10 years ago

+1

kimar commented 10 years ago

thx a bunch, could you please also push an update to npm?

Gottox commented 10 years ago

It's released :)

kimar commented 10 years ago

thx :-)