Memcached sessions and Facebook

Posted by Mike Mangino on Jul 25, 2008

By default, the Memcached session store doesn't allow session keys with dashes in them. Since Facebook session identifiers include a dash, this causes an immediate error. Luckily, there is a simple fix. Add the following code as either an initializer or to your environment.rb file to get your Facebooker sessions running with memcached.

# add - as an okay key
class CGI
  class Session
    class MemCacheStore
      def check_id(id) #:nodoc:#
        /[^0-9a-zA-Z-]+/ =~ id.to_s ? false : true
      end
    end
  end
end

Don't you love simple solutions to annoying problems?