什么是存储在memcached的一个ActiveRecord对象的最佳方式是什么? [英] What is the best way to store an ActiveRecord object in memcached?

查看:182
本文介绍了什么是存储在memcached的一个ActiveRecord对象的最佳方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前有两个问题与存储的ActiveRecord对象memcached中。

There are currently two problems with storing ActiveRecord objects in memcached.

  1. 未定义的类/模块的问题(<一href="http://www.google.com/search?hl=en&safe=off&q=memcached+undefined+class+module&btnG=Search&aq=f&aqi=&aql=&oq=">Google搜索)。从我读了,这仍然是没有人有一个真正好的解决办法的错误。该cache_fu插件有可能是我们的最佳解决方案,其包裹在试图赶上这个错误块检索调用,分析该消息,并尝试加载未定义的类/模块。

  1. The Undefined Class/Module problem (Google search). 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.

臭名昭著的LH票#1339(<一href="https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1339-arbase-should-not-be-nuking-its-children-just-because-it-lost-interest#ticket-1339-54">LH票务)。当你设置为FALSE(开发,测试)cache_classes此错误才会发生。

The infamous LH ticket #1339 (LH Ticket). This bug will only happen when you have cache_classes set to FALSE (development, test).

使用Google的几个星期后,我仍然没有找到一个很好的技术,用于存储AR实例memcached中,而不必应付上面列出的2个问题。

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中,然后从缓存中检索,莫名其妙的想法实例使用这些值的AR对象。这可能吗?如果有,是什么做的最好的方法是什么?

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. Is this possible? If so, what is the best way to do it?

我只是在寻找其他途径Rails开发人员已经解决了这个问题。

I'm just looking for ways other Rails developers have tackled this problem.

推荐答案

在我们的项目中,我们的对象存储为XML。

In our projects we store the object as 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

还有一些额外的费用序列化/反序列化的XML。但是,这使我们能够共享高速缓存之间的非红宝石的应用程序。

There is some extra cost for serializing/de-serializing XML. But this has enabled us to share the cache amongst non Ruby apps.

这篇关于什么是存储在memcached的一个ActiveRecord对象的最佳方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆