cointop-sh / cointop

A fast and lightweight interactive terminal based UI application for tracking cryptocurrencies 🚀
https://cointop.sh
Apache License 2.0
4.05k stars 314 forks source link

Add feature to automatically clear the cache when version upgrade changes format #291

Closed lyricnz closed 2 years ago

lyricnz commented 3 years ago

We've run into an issue a couple of times now where a structure change causes the cache to become invalid/corrupt. It would be good if we could have a "cache format version", and automatically clean the cache if the format changes. See #282

vuon9 commented 2 years ago

I think may be by some way we can automate have a hash version of an empty struct, then we can use it as version hash, and this new implementation should store this hash to the cached data. Anytime, we can generate a new hash for current struct and compare with the hash of struct which is storing in cache. So we can conclude to clear cache or just keep it by the result of comparison.

lyricnz commented 2 years ago

How does golang hashing (of struct instances) work? Would the hash change if a field changed name, but not format?

Could we hash the type object? Or use reflection to generate a unique description of the struct, maybe hashing that, and compare that?

vuon9 commented 2 years ago

Oh, sorry because that was a draft thought. I just tried and seems it could use for both field name and field type, by reflection. Please play with it: https://goplay.tools/snippet/95AlZD8EVmA

The idea of collecting field name came from here: https://stackoverflow.com/a/61465755/1155318

miguelmota commented 2 years ago

Closed by https://github.com/cointop-sh/cointop/pull/302