Skip to content

Feature suggestion: allow direct access to values cached by cache_on_arguments #55

@sqlalchemy-bot

Description

@sqlalchemy-bot

Migrated issue, originally created by Eric Hanchrow ()

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:

#!python

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions