Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Sean Cribbs http://seancribbs.com

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Compress your ActiveRecord sessions

Using ActiveRecordStore and your sessions are getting too big? Try this!

# in environment.rb or some file you require
require 'zlib'
CGI::Session::ActiveRecordStore::Session.class_eval {
  class << self
    def marshal_with_compression(data)
      Zlib::Deflate.deflate(marshal_without_compression(data))
    end
    def unmarshal_with_compression(data)
      unmarshal_without_compression(Zlib::Inflate.inflate(data))
    end
    alias_method_chain :marshal, :compression
    alias_method_chain :unmarshal, :compression
  end
}

# in migration
def self.up
  change_column :sessions, :data, :binary
end

def self.down
  change_column :sessions, :data, :text
end
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS