初始缓存对象代码如下:
pageCache = Cache()
cacheDir = os.path.join(path.dirname(path.dirname(__file__)),'pageCache')
pageCache.init_app(flaskApp,config={'CACHE_TYPE': 'filesystem','CACHE_THRESHOLD':1>>10>>10,'CACHE_DIR': cacheDir })
我使用 pageCache 如下:
class CodeList:
"""
show code list
"""
@pageCache.cached(timeout=60)
def GET(self):
i = web.input()
sort = i.get('sort','newest')
pageNo = int(i.get('page','1'))
if i.get('pageSize'):
pageSize = int(i.get('pageSize'))
else:
pageSize = DEFAULT_LIST_PAGE_SIZE
if pageSize > 50:
pageSize = 50
items = csModel.getCodeList(sort=sort,pageNo=pageNo,pageSize=pageSize)
totalCount = csModel.getCodeCount()
pageInfo = (pageNo,pageSize,totalCount)
return render.code.list(items,pageInfo)
当我请求此页面时,出现异常:
在 /code-snippet/ 处输入“exceptions.RuntimeError”,在请求上下文之外工作
Python C:\Python27\lib\site-packages\flask-0.9-py2.7.egg\flask\globals.py 在 >_lookup_object,第 18 行