WindowsCommunityToolkit icon indicating copy to clipboard operation
WindowsCommunityToolkit copied to clipboard

[Feature] Change `CacheBase.GetCacheFileName` to virtual method

Open Scighost opened this issue 1 year ago • 3 comments

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.

image

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.

Scighost avatar Sep 17 '22 04:09 Scighost

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!

msftbot[bot] avatar Sep 17 '22 04:09 msftbot[bot]

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.

michael-hawker avatar Sep 19 '22 21:09 michael-hawker

IMO both can be done.. it would be good to change default implementation to something that isn't that simplistic.

hermitdave avatar Sep 21 '22 15:09 hermitdave

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.

Arlodotexe avatar Sep 26 '22 16:09 Arlodotexe

Let's look at this holistically in 8.0 where we can make more breaking changes if needed.

michael-hawker avatar Oct 04 '22 16:10 michael-hawker