Rails.cache 和不可转储(Marshal)结构:如何缓存? (在示例 flickraw-response 中)

发布于 2024-10-03 01:48:55 字数 671 浏览 1 评论 0原文

我想用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不知所踪 2024-10-10 01:48:55

我在 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文