Rails.cache 和不可转储(Marshal)结构:如何缓存? (在示例 flickraw-response 中)
我想用 memcached 来 Rails.cache a flickraw 响应(这也适用于其他不可转储的结构),如下所示:
@flickr = Rails.cache.fetch('flickr_sets', :expires_in => 1) { flickr.photos.getRecent }
明显的错误是
TypeError: singleton can't be dumped
我读了 zilkey 关于该问题的一篇好文章,他建议为以下问题构建一个新的转储方法 :那种情况。
http://zilkey.com /2008/7/5/rails-cache-memcached-development-mode-and-offline-cache-invalidation
我的问题是:缓存此类对象的正确方法是什么?我应该编写自己的转储方法吗?是否可以使用 flickr.photos.getRecent.to_s 将对象保存在缓存中作为字符串,然后以某种方式重新加载它?有什么想法吗?
i want to Rails.cache a flickraw response (this is applicable to other un-dumpable structures as well) with memcached as follows:
@flickr = Rails.cache.fetch('flickr_sets', :expires_in => 1) { flickr.photos.getRecent }
the obvious error is
TypeError: singleton can't be dumped
i read a good post on that problem by zilkey, who suggests building a new dump method for that case.
http://zilkey.com/2008/7/5/rails-cache-memcached-development-mode-and-offline-cache-invalidation
my questions are: what would be the right approach to cache that kind of objects? should i write my own dump method? wouldn't it be possible to save the object in the cache with flickr.photos.getRecent.to_s as a String and then somehow reload it? any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在 github tracker 上问了你的问题,因为我也对实现这一目标非常感兴趣。 (参见https://github.com/hanklords/flickraw/issues#issue/16 )
hanklords 似乎已经在当前的提交中修复了这个问题!很棒的事情,我正在尝试在我当前的应用程序中实现这一点。你也可以测试一下吗,z3cko?
https://github.com/hanklords/flickraw/commit/d09db4c5549e72b42eefbf1ea5c98f95bd1bd3d9
i asked your question on the github tracker, since i am also very interested in achieving this. ( see https://github.com/hanklords/flickraw/issues#issue/16 )
hanklords seems to have fixed this in a current commit! great thing, i am trying to implement this in a current app of mine. can you maybe also test it, z3cko?
https://github.com/hanklords/flickraw/commit/d09db4c5549e72b42eefbf1ea5c98f95bd1bd3d9