def cache(func):
@wraps(func)
def wrapper(obj, *args):
key = args[0]
value = _cache.get(key)
if value:
print('get it')
return json.loads(value)
rs = func(obj, *args)
_cache.set(key, json.dumps(rs))
return rs
return wrapper
@classmethod
@cache
def get(cls, id):
rs = cls.objects.get(id=id)
return {
'id': rs.id,
'username': rs.username,
'age': rs.age,
'email': rs.email,
'info': rs.info,
'create_time': str(rs.create_time),
'update_time': str(rs.update_time)
}