memcache 错误键中存在非法字符(Ruby 1.8.7 / Rails 2.3.9)
我在我的一个 Rails 应用程序 [Ruby 1.8.7 + Rails 2.3.9] 中遇到以下错误,
A ArgumentError occurred in home#dashboard:
illegal character in key "dashboard_prod:views/reports/1050 - 097"
/opt/ruby-enterprise/lib/ruby/gems/1.8/gems/activesupport-2.3.9/lib/active_support/vendor/memcache-client-1.7.4/memcache.rb:643:in `get_server_for_key'
我用 google 搜索并发现有人遇到类似的问题: http://www.coffeepowered.net/page/2/
在该页面上提到,这应该有效:
class ActionController::Caching::Actions::ActionCachePath
def path
@cached_path ||= Digest::SHA1.hexdigest(@path)
end
end
但我不确定应该在哪里输入此内容。所以我有两个问题:
- 如何解决手头的问题
- 我应该在哪里编写像上面这样的代码,我们要重写一些标准类或 Gem 中定义的类。
任何帮助将不胜感激。
I am getting the following error in one of my rails app [Ruby 1.8.7 + Rails 2.3.9]
A ArgumentError occurred in home#dashboard:
illegal character in key "dashboard_prod:views/reports/1050 - 097"
/opt/ruby-enterprise/lib/ruby/gems/1.8/gems/activesupport-2.3.9/lib/active_support/vendor/memcache-client-1.7.4/memcache.rb:643:in `get_server_for_key'
I googled and found that someone had similar problem at: http://www.coffeepowered.net/page/2/
on that page it is mentioned that, this should work:
class ActionController::Caching::Actions::ActionCachePath
def path
@cached_path ||= Digest::SHA1.hexdigest(@path)
end
end
But I am not sure where should I type this. So I have two questions:
- How to solve problem at hand
- Where should I write the code like the above where we are overriding some standard class or class defined in a Gem.
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您发现的帖子建议您使用该代码创建一个猴子补丁。使用这些内容在
Rails.root + 'lib/'
下创建一个文件,并确保它在 ActionController (这应该是默认值)之后加载。该补丁将覆盖 ActionController 的默认代码。你肯定想要这样的东西——我总是确保我的内存缓存密钥经过哈希处理。这使它们的调试变得更加困难,但它可以防止出现此类问题,并且当有人创建对于 memcached 来说太长的密钥时,也可以防止出现密钥长度溢出错误。
I think the post you found is suggesting you create a monkey patch with that code. Create a file under
Rails.root + 'lib/'
with those contents, and make sure it loads after ActionController (which should be the default). The patch will override ActionController's default code.You definitely want something like that--I always ensure my memcached keys are hashed. It makes them a little more difficult to debug, but it protects against problems like this and also key-length overflow errors when someone creates a key that's too long for memcached.