作者在 2010-03-27 23:17:25 发布以下内容
web.memoize,貌似是缓存函数返回值的
文档中的实例
| >>> calls = 0
| >>> def howmanytimeshaveibeencalled():
| ... global calls
| ... calls += 1
| ... return calls
| >>> fastcalls = memoize(howmanytimeshaveibeencalled)
| >>> howmanytimeshaveibeencalled()
| 1
| >>> howmanytimeshaveibeencalled()
| 2
| >>> fastcalls()
| 3
| >>> fastcalls()
| 3
| >>> def howmanytimeshaveibeencalled():
| ... global calls
| ... calls += 1
| ... return calls
| >>> fastcalls = memoize(howmanytimeshaveibeencalled)
| >>> howmanytimeshaveibeencalled()
| 1
| >>> howmanytimeshaveibeencalled()
| 2
| >>> fastcalls()
| 3
| >>> fastcalls()
| 3