Comments (6)
Hi,@hanwanhe !
Registry 这个表是所有请求共享的,这个没错,但是每次请求都会执行一个 init_vanilla 方法,这个方法会把每次请求的相关数据重置为当前请求的值,你可以看看这个函数:)
所以不会存在相互覆盖的现象,每个请求拿到的都是自己的。
from vanilla.
那如果我要在controller直接用Registry这个变量呢?
from vanilla.
还有就是当我上面的两个url一起执行的时候,第一个请求的url是生成不了cache的,感觉像是第一个url的cache key被后面一个请求的cache key覆盖掉了。
cache key源码:
Registry['APP_PAGE_CACHE_KEY'] = Registry['REQ_URI'] .. ngx.encode_args(clean_args(Registry['REQ_ARGS_ARR']))
当一个请求没执行完,第二个请求执行的时候会把Registry全局变量修改掉,当第一个请求继续执行的时候,比如说要写cache了,但是Registry['APP_PAGE_CACHE_KEY']其实已经变成第二个请求的了。
from vanilla.
Hi @hanwanhe 对于你的第一个问题,你可以直接用 Registry 这个变量,这个变量存在的意义在于 平凡对 ngx.var
、ngx.req
表进行检索,会带来可观的性能消耗,所以这里把每次请求的相关数据缓存到了 Registry 表中,但是我并没有复现你两次请求 userid
不同导致的结果不一致的问题,请提供最小复现问题的代码包,我好细节看下问题所在。
对于第二个问题,page_cache 的 key 所依赖的 Registry['REQ_URI']
和 Registry['REQ_ARGS_ARR']
变量是每次请求都会被更新的,所以只要请求参数不同的两个请求是不会存在复写的问题,但是如果参数一致的两个请求,本来就该生成相同的 Key 去试图命中缓存。
from vanilla.
function IndexController:index()
--return 'hello vanilla.'
ngx.sleep(10)
print_r(Registry['REQ_ARGS_ARR'])
return 'hello world'
end
这是我的代码,然后在配置文件中,把缓存去掉了,别的都是官方最新版刚安装完成的代码。
唯一要注意的点是要并发去请求不同的Url,当一个请求还没结束的时候,去请求下一个请求,然后第一请求的全局变量就被下一个请求覆盖了。
from vanilla.
@hanwanhe 非常感谢你发现了这个bug,我已经修复了,你可以再试下:)
#104
from vanilla.
Related Issues (20)
- How to install on Windows? HOT 1
- What is the usage (how to use), files under /vanilla/sys/nginx/*.lua HOT 1
- gitbook not found HOT 1
- 中文文档404 HOT 1
- English Docs?
- default template engine suffer from shared global var problem. HOT 1
- lua_code_cache in conf invalid HOT 3
- error: attempt to set ngx.status after sending out response headers HOT 1
- ./configure error HOT 1
- restful路由模式能否实现html后缀 HOT 1
- lua_code_cache关闭后报500错误 HOT 3
- restful.lua
- 启用waf功能报错 HOT 1
- vanilla /opt/openresty/luajit/bin/luajit: /opt/vanilla/bin/vanilla:2: unexpected symbol near '-' HOT 3
- 关于 simple 和 restful 的路由选择 HOT 4
- 解决vanilla多项目使用 resty-template模板缓存问题 HOT 1
- vanilla的restful路由增加对 类似 /web/lua-intro.html 有 - 的url 匹配 HOT 1
- 多项目 路由缓存bug重现 HOT 1
- 最新版 vanilla页面缓存 key 设置不合理。 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vanilla.