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 Request: pass key to should_cache_fn #219

Open
Acbarakat opened this issue Jun 7, 2022 · 6 comments
Open

Feature Request: pass key to should_cache_fn #219

Acbarakat opened this issue Jun 7, 2022 · 6 comments

Comments

@Acbarakat
Copy link

There are some instances where the should_cache_fn should return false based on key information. For example, when the key has some arguments in its string based on date and one does not wish to cache anything matching today and none of this data is in the data object.

@zzzeek
Copy link
Member

zzzeek commented Jun 7, 2022

is this in the context of the get_or_create() method or when using the decorator ?

@Acbarakat
Copy link
Author

My specific content is wanting this feature when I use get_or_create_multi()

@zzzeek
Copy link
Member

zzzeek commented Jun 7, 2022

So there's not a really great way to add that because it would be backwards incompatible. can you do your key-based heuristic before you send the keys in ?

@Acbarakat
Copy link
Author

That's the rub; you may not know which keys (if any) need to be cached until those keys are passed to the creator function. My inelegant workaround is to make a class, save the needs-to-be-cached keys to a class property and pop them in the should_cache_fn. Not very pretty and potentially inaccurate.

@zzzeek
Copy link
Member

zzzeek commented Jun 10, 2022

That's the rub; you may not know which keys (if any) need to be cached until those keys are passed to the creator function.

OK this is not making much sense what use case this could possibly be, you know the key up front, but that's not enough information to know if you can cache the value. the creator function gets the key, and then it generates a value. then afterwards, somehow the combination of the key and the value tells you if you want to cache the value or not.

why not just encode this "should be cached' information with the value you're returning? What is the information specifically ?

@zzzeek
Copy link
Member

zzzeek commented Jun 10, 2022

noting again, I dont immediately see a way to add this feature, unless we 1. do a python inspect() on the given function and decide it's among one of multiple calling styles, which I really don't like having to do that, or 2. we add entirely new arguments for these new functions. In both cases, entirely new flow has to be implemented and tested and carried along to all future APIs that refer to these methods, basically adding maintenance burden forever, but it's for a use case that is extremely unlikely to be generally useful, since so far it seems like it would be very simple to associate the "cachable" status with the value itself.

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