Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
simple file store for rails sessions
module ActionDispatch
module Session
class CustomFileStore < ActionDispatch::Session::AbstractStore
def get_session(env, session_id)
session_data = {}
session_id ||= generate_sid
File.open(tmp_file(session_id),'r') do |f|
data = f.read
session_data = ::Marshal.load(data) unless data.empty?
end rescue nil
[session_id, session_data]
end
def set_session(env, session_id, session_data, options)
File.open(tmp_file(session_id), 'w+') do |f|
encoded = ::Marshal.dump(session_data)
f.write(encoded)
end
session_id
end
def destroy_session(env, session_id, options)
File.unlink tmp_file(session_id)
generate_sid
end
def tmp_file(session_id)
File.join(Rails.root, 'tmp', 'sessions', session_id)
end
end
end
end
@bradpauly

This comment has been minimized.

Copy link
Owner Author

@bradpauly bradpauly commented Aug 12, 2012

Wrote a simple file store while I was researching rails sessions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.