问题:
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