I wanted to do this because I didn't want my web application data stored in a browser's cookie and so either I could use MemCache or the DataStore and I chose memcache. I assume that you have an AppEngine project setup with MERB as your web framework of choice.
All the changes described are located in /war/WEB-INF/config/init.rb
- Load the APIs (place these near the top of init.rb)
# Load the apis
ENV['APPLICATION_ROOT'] = File.join(File.dirname(__FILE__), '..')
require 'appengine-apis/local_boot' - Change the session store from cookie to memcache
c[:session_store] = 'memcache' - Add the following to the Merb::BootLoader.after_app_loads section # This will get executed after your app's classes have been loaded.
Merb::MemcacheSession.store = AppEngine::Memcache.new
module AppEngine
# For the memcache-client gem.
class Memcache
include Merb::MemcacheStore
end
end
The first two and a good portion of the third step are standard Merb as far as I understand (although it took me some digging through the Merb code to find this). The second part of the third step is what I discovered when looking at the source code to see how the standard Memcache gem is integrated into the memcache store. Once I added this mixin AppEngine module, I had session data stored in memcache! Post comments if this works or doesn't work for you and/or if you have any other suggestions, please post so that others can find it!