Skip to content

set_cache default does not work with plugins #792

Open
@Wyko

Description

@Wyko

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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions