Skip to content

Instantly share code, notes, and snippets.

@hirokiky
Created February 24, 2014 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hirokiky/9181666 to your computer and use it in GitHub Desktop.
Save hirokiky/9181666 to your computer and use it in GitHub Desktop.
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