0

I'm very new with Rack and I'm playing around with it, I would love to share some session or hash table among all my rack apps,

Let's say I have the following config.ru

require "rack"
require "./my_app.rb"
require "./auth.rb"

use Rack::Session::Pool, :domain => 'example.com', :expire_after => 60 * 60 * 24
use Auth
run MyApp.new

I want Auth to check user_id in memory, if the request for the first time, then to fitch the data from the db, next time the request with the same id will not trigger User.find, I don't mind any kind of implementation like shared Hash or anything but for this example I used session[], I would highly appreciate it to give me any tip of how to make things work, I'm not looking for real authentication here rather than to share a key among so many ruby processes.

Let's assume that I will run 10 instances of thin rack under nginx, so I would love to share the session/hash with all the processes.

And auth.rb : 

class Auth

  def initialize(app)
    @app = app
  end

  def call(env)     
    @request = Rack::Request.new(env)
    # here I want to find a way to search for key user_id and if I find it do nothing otherwise to set the value for the key 
    session[:user_id] ||= User.find(request.params[:user_id])
    @app.call(env)
  end
end
Eqbal
  • 1,819
  • 2
  • 16
  • 25
  • wat?! what exactly is your question? – phoet Sep 05 '12 at 18:47
  • the above code is not working , i want a way to share data for my processes, just like session above or anyway I can set a key and next time not to update it in case it is not nil .. – Eqbal Sep 05 '12 at 19:38

0 Answers0