aio-libs / aio-libs/aiocache

set_cache default does not work with plugins

オープン
#792 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
1.4k
フォーク
181
PR マージ指標
30日以内にマージされた PR はありません

説明

Using `set_config` with a plugin does not work. You must call it with an alias in order to get it to work.

See below:

```
from aiocache import caches, SimpleMemoryCache, cached

import asyncio

default_cached_config = {
"cache": SimpleMemoryCache,
"plugins": [{"class": "aiocache.plugins.HitMissRatioPlugin"}],
}

caches.set_config({"default": default_cached_config, "my_cache": default_cached_config})

@cached(alias="my_cache")
async def foo():
return "bar"

@cached()
async def default():
return "default bar"

async def main():
print(await foo(), foo.cache.hit_miss_ratio)
print(await default(), default.cache.hit_miss_ratio) # Error here, because default has no plugin

asyncio.run(main())
```
Exception has occurred: AttributeError
'SimpleMemoryCache' object has no attribute 'hit_miss_ratio'
```

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。