简体   繁体   English

在memcached中存储ActiveRecord对象的最佳方法是什么?

[英]What is the best way to store an ActiveRecord object in memcached?

There are currently two problems with storing ActiveRecord objects in memcached. 目前在memcached中存储ActiveRecord对象存在两个问题。

  1. The Undefined Class/Module problem ( Google search ). 未定义的类/模块问题( Google搜索 )。 From what I've read up, this is still a bug that nobody has a real good solution for. 从我读过的内容来看,这仍然是一个没有人有真正好的解决方案的错误。 The cache_fu plugin has probably the best solution for this, wrapping its retrieve call in a block that tries to catch this error, parses the message and tries to load the undefined class/module. cache_fu插件可能是最好的解决方案,将其检索调用包装在试图捕获此错误的块中,解析消息并尝试加载未定义的类/模块。

  2. The infamous LH ticket #1339 ( LH Ticket ). 臭名昭着的LH票#1339( LH票 )。 This bug will only happen when you have cache_classes set to FALSE (development, test). 只有在cache_classes设置为FALSE(开发,测试)时才会发生此错误。

After googling for weeks, I still haven't found a good technique for storing AR instances in memcached without having to deal with the 2 issues listed above. 谷歌搜索几周后,我仍然没有找到一个很好的技术来存储AR实例在memcached中,而不必处理上面列出的2个问题。

The idea I haven't tried yet is removing the attributes from the instance as strings (just how AR receives them from the DB before it does its type casting), storing those in memcached and then on retrieval from the cache, somehow instantiate an AR object using these values. 我还没有尝试过的想法是从实例中删除属性作为字符串(只是AR在进行类型转换之前如何从DB接收它们),将它们存储在memcached中然后从缓存中检索,以某种方式实例化AR使用这些值的对象。 Is this possible? 这可能吗? If so, what is the best way to do it? 如果是这样,最好的方法是什么?

I'm just looking for ways other Rails developers have tackled this problem. 我只是在寻找其他Rails开发人员解决这个问题的方法。

In our projects we store the object as XML. 在我们的项目中,我们将对象存储为XML。

cache.write(user.cache_key, user.to_xml) # write to cache
User.new(Hash.from_xml(cache.read(cache_key))) # reach from cache xml

There is some extra cost for serializing/de-serializing XML. 序列化/反序列化XML需要额外的成本。 But this has enabled us to share the cache amongst non Ruby apps. 但这使我们能够在非Ruby应用程序之间共享缓存。

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

相关问题 将ActiveRecord模型与版本以及它们与版本的关联存储的最佳方法是什么? - What's the best way to store the ActiveRecord Models with Versions and their Associations with Versions? memcached作为Rails中的Object存储 - memcached as an Object store in Rails 从活动记录关系中提取对象的最佳方法 - best way to extract object from an activerecord relation 返回最近在 ActiveRecord 中创建的 object 的最佳方式? - Best way to return recently created object in ActiveRecord? 为memcached和Rails组合片段和对象缓存的最佳方法 - Best way to combine fragment and object caching for memcached and Rails 基于对象属性获取活动记录对象数组的唯一元素的最佳方法是什么? - What is the best way to get unique elements of an array of activerecord objects based on attributes of the object? 存储可定位子记录的最佳方法-ActiveRecord | 滑轨 - Best way to store targetable child records - ActiveRecord | Rails 使用CarrierWave在ActiveRecord中存储许多图像帧的最佳方法 - Best way to store many image frames in ActiveRecord with CarrierWave 在ActiveRecord中存储Enum值并将其转换为字符串以进行显示的最佳方法 - Best way to store Enum value in ActiveRecord and convert to string for display 覆盖Rails ActiveRecord销毁行为的最佳方法是什么? - What is the best way to override Rails ActiveRecord destroy behavior?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM