Feature suggestion: allow direct access to values cached by cache_on_arguments

Issue #55 resolved
Eric Hanchrow
created an issue

I wanted to retrieve the cached value for a function that I'd decorated, but I didn't want to invoke the function in case there was no value. So I wound up doing this:

def cached_value(region, namespace, fn, *args):
    key = region.function_key_generator(namespace, fn)(*args)
    value = region.get(key)
    if value == NO_VALUE:
        return None
    return value

(I realize that conflating "there is no value" with "the value is 'None'" is bad in general, but it was OK in my case.)

Anyway, the above works for me -- but it took me a while to figure out how to write that. Given that you're already providing convenient attributes like "invalidate" and "refresh", perhaps something like this would be useful as another attribute.

Comments (3)

  1. Log in to comment