Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Generating cache key to correspond to functions and it's arguments.
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