Skip to content

Supply cache object to decorator #567

Closed
@padraic-shafer

Description

@padraic-shafer

Is it possible to supply a cache object to the decorator @cached?

It seems like there are two separarte tracks for using aiocache:

  1. Create a cache with the Cache() constructor. This allows inspection and manual reuse of the cache. In particular, this is the track used in the example for plugins, such as inspecting the hit_miss_ratio stats on a HitMissRatioPlugin.
  2. Decorate a coroutine with @cached. This track accepts a class type for a cache rather than a cache object. This nominally allows plugins, and indeed the generated cache object receives and contains the list of plugins. However, the generated cache does not appear to implement the plugin functionality. For example, after passing a HitMissRatioPlugin() object to the plugins parameter of @cached, the cache injected into the coroutine does not have a member called hit_miss_ratio.

Is it possible to pass a cache object, rather than a cache class to the @cached decorator? This would allow the same cache to be shared between multiple function calls. Also it seems to be necessary helpful for utilizing plugin functionality.

On the flip side: Is there a driving force for supplying a cache class (rather than a cache object) to the @cached decorator?

**** Or am I missing something: Dose this functionality already exists and I am simply not using it correctly?

Thanks!

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