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

Can I prevent a cache, when I trow an exception? #209

Closed
p0psicles opened this issue Aug 14, 2021 · 2 comments
Closed

Can I prevent a cache, when I trow an exception? #209

p0psicles opened this issue Aug 14, 2021 · 2 comments

Comments

@p0psicles
Copy link

This is more a user question then an issue.
But I was looking for a way to cache a result, if that result is for example None.

@recommended_series_cache.cache_on_arguments()
def cached_get_imdb_series_genres(imdb_id):
    """
    Request the series genres from the api.

    Use dogpile cache to return a cached id if available.
    """
    genres = api.get_title_genres(imdb_id)
    if not genres:
        raise Exception(f'Could not get imdb genres from {imdb_id}')
    return genres

Would this prevent it from being dogpile cached?

@zzzeek
Copy link
Member

zzzeek commented Aug 14, 2021

caching can be prevented if you raise an exception but that would raise an exception overall. what do you want the return value of cached_get_imdb_series_genres() to be when you can't get the genres? if you want it to just raise, then you can raise, there's nothing it can cache in that case.

@p0psicles
Copy link
Author

I'm catching the thrown exception now. And that works. Before the API call would return None. And then that was cached.

So it's working nicely now. Tnx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants