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

an issue with cache make the entire function fail! #28

Open
eyalk11 opened this issue Aug 30, 2024 · 1 comment
Open

an issue with cache make the entire function fail! #28

eyalk11 opened this issue Aug 30, 2024 · 1 comment

Comments

@eyalk11
Copy link

eyalk11 commented Aug 30, 2024

    def wrapper(*args, **kwargs):
        """The actual wrapper"""
        nonlocal hits, misses
        key = make_key(args, kwargs)
        value = cache.get(key, sentinel)
        if value is not sentinel and values_toolkit.is_cache_value_valid(value):
            with lock:
                hits += 1
            return values_toolkit.retrieve_result_from_cache_value(value)
        else:
            with lock:
                misses += 1
            result = user_function(*args, **kwargs)
            cache[key] = values_toolkit.make_cache_value(result, ttl)
            key_argument_map[key] = (args, kwargs)
            return result

cache.get fails on exception in hash_ function of one of the args.

Why does it cause the entire function to fail?
Why there is no try..catch around it?

@eyalk11
Copy link
Author

eyalk11 commented Aug 30, 2024

Here is my fixed func

    def wrapper(*args, **kwargs):
        """The actual wrapper"""
        nonlocal hits, misses


        try:
            key = make_key(args, kwargs)
            value = cache.get(key, sentinel)
        except:
            warnings.warn(f"cache get failed { key}")
            value = sentinel

        if value is not sentinel and values_toolkit.is_cache_value_valid(value):
            with lock:
                hits += 1
            return values_toolkit.retrieve_result_from_cache_value(value)
        else:
            with lock:
                misses += 1
            result = user_function(*args, **kwargs)
            try:
                cache[key] = values_toolkit.make_cache_value(result, ttl)
                key_argument_map[key] = (args, kwargs)
            except:
                warnings.warn(f"make key  failed { result}")
            return result

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

1 participant