Migrating ApnaBill.com to SqlSessionStore
Rails2′s client side sessions were starting to give us troubles as we were ‘kinda’ overshooting the 4kb limit almost every now and then. Idealists would say that thats a bad practice – and I agree – but the changes now run too deep to fix them, withought having to change/throw a lot of code.
It seemed much better to fall back to server side sessions than client side. A quick search and ActiveRecordStore is one of the chosen techniques after PStore. Another quick search and you’ll come across SqlSessionStore which is much faster than ActiveRecordStore. [Comparison of various session management techniques]
Installation and configuration was super quick (thanks to the plugin) – follow the README.
However, one issue that you’ll need to address is to get mysql-ruby installed.
The next issue that’ll stare at you in the face is to constantly keep the sessions table cleaned up. And I faced a peculiar problem solving this. The timestamps of “updated_at” were running 4 hours behind the Time.now value. So stock solutions available for this problem were not working perfectly. I had to subtract an offset of “4.hours” from XX.minutes.ago value to get the correct timeouts.
desc "Cleans up stale sessions." task :clean_stale_sessions => :environment do # Determined by manual inspection. offset = 4.hours CGI::Session::ActiveRecordStore::Session.destroy_all( ['updated_at <?', YOUR_TIMEOUT.minutes.ago - offset] ) end
Hence Solved Bug #69, which solved Bug #67 and Bug #15 – wheehaa!
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.








