]> git.openstreetmap.org Git - rails.git/blob - config/initializers/session_store.rb
Link to the Markdown spec
[rails.git] / config / initializers / session_store.rb
1 # Be sure to restart your server when you modify this file.
2
3 if defined?(MEMCACHE_SERVERS)
4   unless STATUS == :database_offline or STATUS == :database_readonly
5     module Rack
6       module Session
7         class Memcache
8           def get_session(env, sid)
9             with_lock(env, [nil, {}]) do
10               unless sid and session = @pool.get(sid)
11                 if sid and s = ActiveRecord::SessionStore::SqlBypass.find_by_session_id(sid)
12                   session = s.data
13                   s.destroy
14                 else
15                   sid, session = generate_sid, {}
16                 end
17                 
18                 unless /^STORED/ =~ @pool.add(sid, session)
19                   raise "Session collision on '#{sid.inspect}'"
20                 end
21               end
22               [sid, session]
23             end
24           end
25         end
26       end
27     end
28   end
29
30   cache = MemCache.new(:namespace => "rails:session", :string_return_types => true)
31
32   OpenStreetMap::Application.config.session_store :mem_cache_store, :cache => cache, :key => "_osm_session"
33 else
34   OpenStreetMap::Application.config.session_store :cache_store, :key => '_osm_session'
35 end