开发者

memcache error illegal character in key (Ruby 1.8.7 / Rails 2.3.9)

开发者 https://www.devze.com 2023-03-08 13:46 出处:网络
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:

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:

  1. How to solve problem at hand
  2. Where should I write the code like the above where we are ov开发者_StackOverflow中文版erriding some standard class or class defined in a Gem.

Any help would be appreciated.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消