1

I want to store temporary data that can be accessed across multiple http request. The question may be similar to How to persist temporary data over multiple HTTP requests?. The accepted answer is too specific to ASP. However, in my case i'm using rails as the framework. I want to know possible pattern that at least will solve the problem on my environment and use case.

Environtment: Server side:

  • Rails 4
  • Redis
  • postgresql
  • Sidekiq

Client Side:

  • Chrome / Firefox

Use case: Client make a request to create an object on server side, and make the object accessible at least one day in multiple http connection. The data to store is a hash with value of strings, a long strings, that can take up to thousands of characters.

I tried few different approach to accomplish this, for example :

  • List item Using temporary database object.

    I created a column to mark the data as temporary. And i created a worker to delete the temporary data everyday.

    The problem with this approach is create alot of temporary data and make the database dirty.

  • Using cookie as the storage

    Cookie is great choice but is it can hold up string with thousands of chars ?

Is there any better approach for me to store temporary data ? The pattern that works in rails will be acceptable, but it will be better if it is general and can be applied to different framework.

1

What you are looking for is as some kind of (HTTP) Session. You can uses a cookie to store the reference id within your session store.

You already using Redis and Redis is a "perfect" persistence to store session data. All operations are performed in memory, and so reads and writes will be fast.

Redis provides a way to set the time to live or the entries so there is no need for a cleanup job.

There is a GitHub project called https://github.com/roidrage/redis-session-store

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.