問題:
For caching purposes I need to generate a cache key from GET arguments which are present in a dict.出於緩存目的,我需要從 dict 中存在的 GET 參數生成緩存鍵。
Currently I'm using sha1(repr(sorted(my_dict.items())))
( sha1()
is a convenience method that uses hashlib internally) but I'm curious if there's a better way.目前我正在使用sha1(repr(sorted(my_dict.items())))
( sha1()
是一種在內部使用hashlib的便捷方法)但我很好奇是否有更好的方法。
解決方案:
參考一: https://en.stackoom.com/question/OgiI參考二: https://stackoom.com/question/OgiI