WindowsCommunityToolkit
WindowsCommunityToolkit copied to clipboard
[Feature] Change `CacheBase.GetCacheFileName` to virtual method
Describe the problem
There are two urls: https://file.xunkong.cc/genshin/talent/UI_Talent_S_Shougun_06.png https://file.xunkong.cc/genshin/talent/UI_Talent_U_Shougun_02.png
When I cache them via FileCache, they are treated as the same file because the default hash algorithm is too simple. This problem has happened at least 10 times in my application.
Describe the solution
Change CacheBase.GetCacheFileName
to virtual method, letting developer can custom the file name.
- private static string GetCacheFileName(Uri uri)
+ protected virtual string GetCacheFileName(Uri uri)
Alternatives
Use a more complex default hash algorithm instead of CacheBase.CreateHash64
.
Additional info
No response
Help us help you
Yes, I'd like to be assigned to work on this item.
Hello, 'Scighost! Thanks for submitting a new feature request. I've automatically added a vote 👍 reaction to help get things started. Other community members can vote to help us prioritize this feature in the future!
Thanks for reporting this issue @Scighost. Definitely an interesting scenario. Does seem like the hash algorithm is weak here.
Wondering if it's worth improving it vs. exposing the internal method (as that's really just an implementation detail). Ideally the cache should just work.
@hermitdave @azchohfi @Sergio0694 @Arlodotexe wondering if you have any thoughts here.
IMO both can be done.. it would be good to change default implementation to something that isn't that simplistic.
Making GetCacheFileName
virtual is a good "fast" solution to unblock users now, but we really should be using SHA256 or Kekkak/SHA-3 to avoid hash collisions properly.
Changing the hashing algorithm is a potentially breaking change. If we do, we'll need to keep the previous one around so it can still find files that were cached by older code.
Let's look at this holistically in 8.0 where we can make more breaking changes if needed.