aio-libs / aio-libs/aiocache

set_cache default does not work with plugins

Aperta
#792 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
1.4k
Fork
181
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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'
```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.