Closed lyricnz closed 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.
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?
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
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