Skip to content

Implement @cached_many #6

Description

@eigenein

Suggested use case:

@cached_many(cache)
def expensive_function(items: Iterable[K], …) -> Mapping[K, V]:
    …

expensive_function(["foo", "bar", "qux"], …)

Expected behaviour

expensive_function should get called only on items which aren't present in the cache. Pseudo-code:

cached_items = cache.get_many(*items)
new_items = wrapped_function(*(item for item in items if item not in cached_items), *args, **kwargs)
cache.set_many(new_items)
return {**cached_items, **new_items}

Discussion

  • Should @cached_many allow specifying of the items parameter by index or keyword argument name?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions