Skip to content

Commit

Permalink
README updated
Browse files Browse the repository at this point in the history
  • Loading branch information
vlado committed Apr 21, 2012
1 parent 24f8ee7 commit f358b82
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ Rails engine to simply save big temporary data (too big for session cookie store
Why
---
While working on [Padbase](http://www.padbase.com) we needed [2 steps signup process](http://www.padbase.com/pads/new) (1. enter property info, 2. enter user info). Info entered in first step could get very large and we couldn't save it in a session because of [CookieOverflow](http://api.rubyonrails.org/classes/ActionDispatch/Cookies/CookieOverflow.html), didn't want to switch to ActiveRecord store and didn't want to save invalid property in database with the flag (partial validations, ...). Solution was to create separate table for this temporary data and RailsTemporaryData was born.

**This way you get best from both worlds. Standard session data is still saved in a cookie and you can save larger amount of data in a database.**

Install
-------

Start by adding the gem to your application's Gemfile

gem 'rails_temporary_data', :git => 'git://github.com/vlado/rails_temporary_data.git'
gem 'rails_temporary_data'

Update your bundle

Expand All @@ -30,48 +31,48 @@ Run migration
Example
--------

class DummyController < ApplicationController
class DummyController < ApplicationController

def set_data
set_tmp_data("some_key", { first_name: "Vlado", last_name: "Cingel", bio: "Very ... very long bio" })
...
end
def set_data
set_tmp_data("some_key", { first_name: "Vlado", last_name: "Cingel", bio: "Very ... very long bio" })
...
end

def get_data
tmp_data = get_tmp_data("some_key").data
# do something with tmp data
first_name = tmp_data[:first_name] # => Vlado
...
end
def get_data
tmp_data = get_tmp_data("some_key").data
# do something with tmp data
first_name = tmp_data[:first_name] # => Vlado
...
end

end
end

You can optionally set data expiry time (default is 2 days)

class DummyController < ApplicationController
class DummyController < ApplicationController

def set_data
set_tmp_data("some_key", { first_name: "Vlado", last_name: "Cingel", bio: "Very ... very long bio" }, Time.now + 3.days)
...
end
def set_data
set_tmp_data("some_key", { bio: "Very ... very long bio" }, Time.now + 3.days)
...
end

end
end

To clear data you don't need any more

class DummyController < ApplicationController
class DummyController < ApplicationController

def get_data
tmp_data = get_tmp_data("some_key").data
# do something with tmp data
clear_tmp_data("some_key")
end
def get_data
tmp_data = get_tmp_data("some_key").data
# do something with tmp data
clear_tmp_data("some_key")
end

end
end

To help you clear unwanted and/or expired data rake task is provided. You should set a cron job to call this task daily.

rake rails_temporary_data:delete_expired
rake rails_temporary_data:delete_expired


TODO
Expand Down

0 comments on commit f358b82

Please sign in to comment.