aio-libs / aio-libs/aiocache

Wrap functions in class with decorator

未關閉
#625 7 則留言 2 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
1.4k
分支
181
PR 合併指標
30 天內沒有已合併 PR

描述

The decorator should be simplified to a simple function, which should then return an object which wraps the passed function. Something along the lines of:
```
class Wrapper:
def __init__(self, func):
self.func = func

def __call__(self, *args, **kwargs):
# Get from cache...
# Or call self.func(*args, **kwargs)

def cached(func):
return Wrapper(func)
```

This simplifies the logic, and makes it easy to add methods on to our function (related: #538). For example, to call the function while forcing the cache to update could look something like:
```
@cached
def foo(...):
...

# Force update
foo.refresh(...)
```

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。