将标准functools展开为方法
methodtools的Python项目详细描述
将functools特性扩展到methods、classmethods、staticmethods,甚至 (非官方)混合方法。
使用methodtools模块而不是functools模块。它的作用是 你预料到了。
frommethodtoolsimportlru_cacheclassA(object):# cached method. the storage lifetime follows `self` object@lru_cache()defcached_method(self,args):...# cached classmethod. the storage lifetime follows `A` class@lru_cache()@classmethod()defcached_classmethod(self,args):...# cached staticmethod. the storage lifetime follows `A` class@lru_cache()@staticmethod()defcached_staticmethod(self,args):...@lru_cache()# just same as functools.lru_cachedefcached_function():...
文档
目前,methodtools只提供lru缓存。 例如,见上文。 有关参数的详细信息,请参阅functools.lru_cache的文档。
另请参见
这个项目来自Ring, 使用相同方法处理技术的富缓存接口。