skip to Main Content

I’m using dogpile.cache in a Python project, with a pylibmc based backend. After creating a region I use something like:

@region.cache_on_arguments()
def run_some_query(**kwargs):
    # ... Query code ...
    return query_results

My problem is, that there are certain exceptions that the decorator raises, that I would simply like to ignore. For instance if memcached is not available, or if the result is too large.

Is there a way to achieve this without rolling my own custom decorator? And if I have to create a custom decorator, what is good way to achieve that.

2

Answers


  1. Chosen as BEST ANSWER

    I have managed to solve this problem. As it turns out, the solution was in the dogpile.cache documentation after all, and I missed it. The solution can be found in the section Changing Backend Behavior in the documentation. The idea is simple: create a proxy backend as described in the documentation, and then use the wrap parameter when configuring the region to include this proxy backend.


  2. Decorators are just functions. So you would need to alter functions.
    Python has no way of disabling the exception in existing functions.

    You may inherit the class where this exception handling occurs and override this method.

    Except, there is a way but it involves tracing, and you need to be careful.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search