简体   繁体   English

如何在宝石中获取rails config.cache_store配置?

[英]How to get rails config.cache_store config in a Gem?

So, I'm developing my first gem that needs some real connection with rails. 因此,我正在开发我的第一个需要与导轨真正连接的宝石。 It needs to know what is configured into config.cache_store. 它需要知道在config.cache_store中配置了什么。 How do I get this info? 我如何获得此信息?

A little more background about it: it's a memcached manager(compatible only with Dalli gem, on it's first version) like resque-web for resque. 关于它的更多背景信息:它是一个内存缓存管理器(仅与Dalli gem兼容,在其第一个版本上),类似于resque-web for resque。 I've tried reading resque code and it's case is different as it has a initializer for it and the Redis config is loaded from a yml file. 我尝试读取resque代码,但情况有所不同,因为它具有初始化程序,并且Redis配置是从yml文件加载的。

Thanks in advance. 提前致谢。

config.cache_store is loaded into two different places: config.cache_store被加载到两个不同的位置:

Rails.cache
ActionController::Base.cache_store

...which are both defaulted from config.cache_store, but can optionally be configured separately. ...都是config.cache_store的默认值,但是可以选择单独配置。 You should be able to inspect one/both of these depending on what you need to determine the cache config at runtime. 您应该能够根据需要在运行时确定缓存配置的基础上检查其中之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM