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

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

Closed
sqlalchemy-bot opened this issue Jan 6, 2014 · 4 comments

Comments

@sqlalchemy-bot
Copy link

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.

@sqlalchemy-bot
Copy link
Author

Michael Bayer (zzzeek) wrote:

oh like a .get() ? sure. send me a pullreq. But it should return the NO_VALUE directly, "None" can be a cached value in the general sense.

@sqlalchemy-bot
Copy link
Author

Eric Hanchrow () wrote:

I created pull request #12.

@sqlalchemy-bot
Copy link
Author

Michael Bayer (zzzeek) wrote:

resolved in pullreq 12.

@sqlalchemy-bot
Copy link
Author

Changes by Michael Bayer (zzzeek):

  • changed status to closed

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

No branches or pull requests

1 participant