python - Django: plugging into database layer to register all queries -


in django project (currently using django 1.9), have decorator make function return values cached until changes in specific database models.

def cached(*names_of_classes):     def decorator(f):          def wrapper(*args,**kwargs):               """               checking if cached result f same args, kwargs               , cache generation of names_of_classes exists               """ 

i have code in base class models update cache generation on changes.

however means manually specifying classes function call depends on, bug-prone , not dry. far more elegant being able somehow record classes queries when running function on cache miss, , use list of classes (or possibly single instances if direct query made) cache invalidation.

is possible to

  1. plug django orm database layer model classes or instances queried
  2. somehow getting information not logged place, stored somewhere each thread can ask "which queries made during calling f , calls within that"? i'm mot sure if better involves thread-local variable, or introspection?

i rather not have annotate each return return value calls within f "classes value depends on" , pass on; such solution (2) meaning having change both django orm , every line of own , third-party code. "out-of-band" solution handy.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -