Coder Social home page Coder Social logo

Comments (6)

idevz avatar idevz commented on May 14, 2024

Hi,@hanwanhe
Registry 这个表是所有请求共享的,这个没错,但是每次请求都会执行一个 init_vanilla 方法,这个方法会把每次请求的相关数据重置为当前请求的值,你可以看看这个函数:)
所以不会存在相互覆盖的现象,每个请求拿到的都是自己的。

from vanilla.

hanwanhe avatar hanwanhe commented on May 14, 2024

那如果我要在controller直接用Registry这个变量呢?
qq 20170710180016
qq 20170710180034
qq 20170710180043

from vanilla.

hanwanhe avatar hanwanhe commented on May 14, 2024

还有就是当我上面的两个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.

idevz avatar idevz commented on May 14, 2024

Hi @hanwanhe 对于你的第一个问题,你可以直接用 Registry 这个变量,这个变量存在的意义在于 平凡对 ngx.varngx.req 表进行检索,会带来可观的性能消耗,所以这里把每次请求的相关数据缓存到了 Registry 表中,但是我并没有复现你两次请求 userid 不同导致的结果不一致的问题,请提供最小复现问题的代码包,我好细节看下问题所在。
对于第二个问题,page_cache 的 key 所依赖的 Registry['REQ_URI']Registry['REQ_ARGS_ARR'] 变量是每次请求都会被更新的,所以只要请求参数不同的两个请求是不会存在复写的问题,但是如果参数一致的两个请求,本来就该生成相同的 Key 去试图命中缓存。

from vanilla.

hanwanhe avatar hanwanhe commented on May 14, 2024

function IndexController:index()
--return 'hello vanilla.'
ngx.sleep(10)
print_r(Registry['REQ_ARGS_ARR'])
return 'hello world'
end

这是我的代码,然后在配置文件中,把缓存去掉了,别的都是官方最新版刚安装完成的代码。
唯一要注意的点是要并发去请求不同的Url,当一个请求还没结束的时候,去请求下一个请求,然后第一请求的全局变量就被下一个请求覆盖了。

from vanilla.

idevz avatar idevz commented on May 14, 2024

@hanwanhe 非常感谢你发现了这个bug,我已经修复了,你可以再试下:)
#104

from vanilla.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.