1

I have an api call which according to some passed values such as budget and time , returns a list of projects. There will be 100s of projects with there data passed as a json list of objects. I want to cache this result so that I dont have to connect to the backend database every time. I am using flask python for the api dev. Is this kind of code is sufficent taken from Flask Cache doc:

@cache.cached(timeout=50, key_prefix='all_comments')
def get_all_comments():
  comments = do_serious_dbio()
  return [x.author for x in comments]
cached_comments = get_all_comments()

Or is there another way to do that? My return Json is like:

{ "some_attr" : ,
  "another_attr": ,
  "list of projects": [ {"name": ,"budget" : } ...]
}
DragneelFPS
  • 453
  • 4
  • 12
  • Can you use local storage on the user's machine? Is this an internal tool or a tool used by thousands/millions of users? How large is the data in KB? – Scott Dec 03 '17 at 17:23
  • 1
    I'm developing a web application or site. Currently the data is not huge but it will be in future. The problem is with excessive multiple calls for the same query will return same data (which might change in long duration. of time) but not going to change in frequent calls. – DragneelFPS Dec 03 '17 at 17:27
  • Can you cache the data on the user's machine? – Scott Dec 03 '17 at 17:28
  • Perhaps you want to write the response to a file for later retrieval and invalidate that cached file at some point in the future. Hard to say without more info. – Scott Dec 03 '17 at 17:29
  • I was thinking of using browser caching somehow. – DragneelFPS Dec 03 '17 at 18:46

0 Answers0