Generating cache key to correspond to functions and it's arguments.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from hashlib import sha1 | |
def default_key_generator(func, *args, **kwargs): | |
""" モジュール名、関数名 + 文字列化した引数から生成したsha1をキーとするキャッシュ用キー生成関数 | |
""" | |
func_identifier = '{func.__module__}:{func.__name__}'.format(func=func) | |
arg_identifier = 'args:{args}kwargs:{kwargs}'.format(args=args, kwargs=kwargs) | |
return sha1(func_identifier + '::' + arg_identifier).hexdigest() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment