关于ETAG的一些使用方式
参考
ETAG介绍: https://harttle.land/2017/04/04/using-http-cache.html
ETAG的hash方式: https://cloud.google.com/storage/docs/hashes-etags?hl=zh-cn
实现案例 https://github.com/matthewbdaly/laravel-etag-middleware
常规模式 (可以用AOP的方式已中间件的形式,配合任意的Action使用,对Handle的逻辑无侵入)
节省带宽,不节省运算资源, 不使用服务端缓存
handle(request,response)
if hash(response.body.stream) == resquest.header.get('ETAG')[0] {
return response.withNotModify()
}
上下文Hash模式(有局限性)
将上下文中的信息hash后,放入服务的缓存。 节省了资源,又节省了带宽 类似:
//set cache
cache.set(hash(context),hash(body))
if cache.get(hash(context)) == request.header.get('ETAG')[0] {
return response.withNotModify()
}
欢迎补充