如何正确缓存返回大量对象的REST API的结果

时间:2017-12-03 16:57:34

标签: python json caching flask flask-cache

我有一个api调用,根据一些传递的值,如预算和时间,返回一个项目列表。将有100个项目将数据作为json对象列表传递。我想缓存此结果,以便我不必每次都连接到后端数据库。我正在使用flask python for api dev。这种代码是否足以从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()

或者还有另一种方法吗?我的回归Json就像:

{ "some_attr" : ,
  "another_attr": ,
  "list of projects": [ {"name": ,"budget" : } ...]
}

0 个答案:

没有答案