Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement @cached_many #6

Open
eigenein opened this issue Jun 14, 2022 · 0 comments
Open

Implement @cached_many #6

eigenein opened this issue Jun 14, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@eigenein
Copy link
Member

eigenein commented Jun 14, 2022

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?
@eigenein eigenein added the enhancement New feature or request label Jun 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant