Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
82 views
in Technique[技术] by (71.8m points)

python - Backend Cache not Shared with Django

I've created a python package that does some expensive computation and uses lru_cache in order to save the result so the user don't have to wait too long for the result being calculated.

import cachetools.func

@cachetools.func.ttl_cache(ttl=60*60)
def main_function():
  # some expensive computations
  return result

The code works pretty well when I call directly the function from a file or from the Python Shell, my issue is that when calling this package from my Django project, somehow it doesn't look up the already cached results.

In my __init__.py file I'm calling main_function and then I try to call it again from my Django project but it does not return the cached response, instead it runs the function again.

The package that I've created has a complex cache system, it works nice so I think this may be a problem with Django, that somehow I need to manage the caches from my Django project, any suggestions on how can I solve this?

question from:https://stackoverflow.com/questions/65871366/backend-cache-not-shared-with-django

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...