简体   繁体   English

使用Rails 3配置Memcached

[英]Configure Memcached with Rails 3

I'm having problems trying to use Memcached in a Rails 3 Application ... 我在尝试在Rails 3应用程序中使用Memcached时遇到问题...

My question is quite simple : How I'm supposed to configure Memcached to make it works with Rails 3 ? 我的问题很简单: 我应该如何配置Memcached以使其与Rails 3兼容?

Thanks for your help ! 谢谢你的帮助 !

Edit: 编辑:

It looks like the object isn't correctly deserialized by the Rails.cache.read no matter :raw => true or :raw => false but the deserialization is working if it's done just after the Rails.cache.write 不管:raw => true还是:raw => false无论Rails.cache.read是否正确反序列化该对象,但是如果在Rails.cache.write之后完成反序列化,则该反序列化将起作用

Ok so, 好吧

Complete context : 完整内容:

The serialized object had his Class into a Lib files. 序列化的对象将其Class放入Lib文件中。 The lib files are auto loaded by rails using using the standard naming convention. lib文件是使用标准命名约定由rails自动加载的。 The Rails.cache.read was the first step of any actions in my application (except the init action which creates the object for the first time). Rails.cache.read是我的应用程序中任何操作的第一步(除了init操作是首次创建对象)。 So, i had an error on any other action : undefined method for String . 因此,我在执行任何其他操作时出错: undefined method for String This was because the Rails.cache.read was returning me a String (serialized object) instead of my object instance. 这是因为Rails.cache.read我返回了一个String(序列化对象)而不是我的对象实例。

Explanation : 说明:

It looks like Marshal doesn't use the Rails system to find Undeclared constants. 看来Marshal没有使用Rails系统来查找未声明的常量。 So, when i was calling Rails.cache.read the Marshal.load was falling and read was returning the String without throwing any error. 因此,当我调用Rails.cache.readMarshal.load下降并且read返回了String而不抛出任何错误。

The Solution : 解决方案 :

I simply added a load of my lib in my application controller. 我只是在我的应用程序控制器中添加了我的库的load That way, all the constants are already loaded when Rails.cache.read calls Marshal.load Note that i used load instead of require in development mode to avoid to have to restart my server after each modification. 这样,当Rails.cache.read调用Marshal.load时,所有常量都已加载。请注意,在开发模式下,我使用load而不是require来避免每次修改后都必须重新启动服务器。

Hopefully this will help someone. 希望这会帮助某人。

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

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