request_store_rails::package:为多线程应用程序准备的Rails的按请求全局存储 源码
RequestLocals 如果您曾经需要在Rails中使用全局变量,那么就知道它很烂。 通常的技巧之一是使用Thread.current ,或者如果您已完成作业,则使用很棒的 。 # Using Thread.current def self . foo Thread . current [ :foo ] ||= 0 end def self . foo = ( value ) Thread . current [ :foo ] = value end # Using RequestStore def self . foo RequestStore . fetch ( :f
下载地址
用户评论