Flask回掉接入点简单实现静态页面缓存
来源:互联网 发布:韩都衣舍淘宝 编辑:程序博客网 时间:2024/06/06 02:57
再多的描述不如看代码,详细注释的代码。
#coding:utf8from werkzeug.contrib.cache import SimpleCache#引入werkzeug.contrib.cache里面的缓存类from flask import request,render_template#引入模板CACHE_TIMEOUT = 300#定义个属性超时cache = SimpleCache()#生成一个SimpleCache对象cache.timeout =CACHE_TIMEOUT#设置超时时间@app.before_request#此函数在所有i请求之前执行def return_cached(): if not request.values: #如果用户没有提交参数,values是存提交参数。 response =cache.get(request.path) #就在缓存中检查当前页面是否存在 if response: #如果存在 return response #返回缓存@app.after_request#在所有请求最后执行def cache_response(response): if not request.values: #如果客户端未提交任何参数 cache.set(request.path,response,CACHE_TIMEOUT) #认为此次返回结果具有典型性,将其存到缓存对象,以便后续访问 return response #执行返回@app.route("/get/index")def index(): return render_template('index.html')
阅读全文
0 0
- Flask回掉接入点简单实现静态页面缓存
- 使用ob缓存简单实现页面静态化
- ob缓存实现页面静态化
- php-ob缓存实现页面静态化
- tp3.2实现简单的静态缓存
- 简单实现flask route
- 缓存静态页面
- 缓存静态页面类
- 普通静态页面缓存
- ob静态页面缓存
- Varnish+ESI实现静态页面的局部缓存
- 使用Varnish+ESI实现静态页面的局部缓存
- 使用smarty模板或缓存实现页面静态化
- 使用Varnish+ESI实现静态页面的局部缓存
- python+flask实现简单博客
- flask-cache 之缓存cache实现原理
- php 模板替换实现静态页面简单代码实现
- php缓存—静态页面
- php发送post请求的三种方法
- 一头扎进springboot之使用Freemarker模板引擎渲染web视图
- Django QuerySet API
- Mysql read lock and write lock
- css居中解决方案及思考
- Flask回掉接入点简单实现静态页面缓存
- 关于进行安装程序出现注册DLL/OCX失败,返回码:0x5问题
- 关于修改select样式的方法
- RabbitMq、ActiveMq、ZeroMq、kafka之间的比较
- 设计模式 -- 单例模式
- 从机器学习算法的发展 理解 端到端(end to end)学习
- qcom 显示驱动注册流程
- Tensorflow--useful function
- centos7 nginx安装与配置实现负载均衡