@cached_property

from django.utils.functional import cached_property
import datetime

class User(object):
    birth_year = 1988

    @cached_property
    def age(self):
        return datetime.date.today().year - self.birth_year

if __name__ == '__main__':
    u = User()
    print(u.age)
    print(u.age)
  
  #结果
  32
  32

  

上一篇:页面资源访问提示“Refused to load the script xxxxxx because it violates the following Content Security Policy


下一篇:No cached version of com.android.tools.build:gradle:3.6.2 available for offlin 解决办法