In my current project, I had to store some temporary data for a user and let a few background processors have access to it. I wrote something small with a dependency on Redis which does the job.
It allows me to use current_user.tmp[:token_id] = "somedata here"
and then access it
in the background processor using user.tmp[:token_id]
which I think is pretty neat.
Moreover, since my use case needed this for temporary storage, I set it to auto expire in 1 day. If yours is different you could change that piece of code.
1 | # /app/models/user_tmp.rb |
And here is the user class
1 | # /app/models/user.rb |
Hope you find it useful :)
I am currently working on LiveForm which makes
setting up contact forms on your website a breeze.