jaredwray / flat-cache

A stupidly simple key/value storage using files to persist the data
MIT License
165 stars 30 forks source link

Circular References (related to persitify) #5

Closed nopnop closed 8 years ago

nopnop commented 8 years ago

Hello,

I came across a problem with persistify that is related to flat-cache (persistify is really awesome by the way)

Sometimes, browserify cache may contain circular reference that break flat-cache serialization. I fixed this by replacing JSON.stringify by json-stringify-safe in cache.js#L109. But it may not be a good solution so I won't push a PR before having your perspective on this.

Maybe for a caching mechanism, highly related to development purpose, it's acceptable to fallback to something like json-stringify-safe. At least with a warning instead of a fatal Exception or with a lenient options to optionally use json-stringify-safe instead of JSON.stringify ?

royriojas commented 8 years ago

hi @nopnop,

that's interesting, I never came to a situation like that, maybe this is a chance to try https://github.com/WebReflection/circular-json. That library claims to be able to serialize circular references. might be worth.

The problem is that if we cannot recreate the cache as it is then it will be a real problem as I bet the bundle won't be useful.

If you can give it a try I'm more than happy to review/merge.

Let me know.

nopnop commented 8 years ago

Nice, I'll give a try with https://github.com/WebReflection/circular-json Circular dependency is usually the result of a bad-design (It could append with a require inside a function for instance). Anyway, this may appeared in third-party library. I'll keep you up-to date