# Sessions

**URL:** <https://www.ruby-forum.com/t/sessions/187592>\
**Category:** Rails\
**Created:** [April 26, 2010, 2:23pm UTC](https://www.ruby-forum.com/t/sessions/187592 "2010-04-26T14:23:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mailtorajuit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed8c4c/32.png) [@mailtorajuit](https://www.ruby-forum.com/u/mailtorajuit)\
**Post date:** [April 26, 2010, 2:23pm UTC](https://www.ruby-forum.com/t/sessions/187592/1 "2010-04-26T14:23:08Z")

</div>

hi all,

in my application, i have login form. while login into the application  
iam maintaning the details in session. i want to remove the stale  
sessions and while removing the stale sessions i want to perform some  
operattions on database . how to do this.

Regards,  
Rajkumar

---

<div class="post-metadata">

**Author:** ![mailtorajuit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed8c4c/32.png) [@mailtorajuit](https://www.ruby-forum.com/u/mailtorajuit)\
**Post date:** [April 27, 2010, 5:59pm UTC](https://www.ruby-forum.com/t/sessions/187592/2 "2010-04-27T17:59:02Z")

</div>

On 27 Apr 2010, at 17:44, Andy J. wrote:

> The other way is to have a version field checked/set in a filter in  
> your application and empty any incoming session requests if they  
> don’t have the right version. It won’t delete them all immediately,  
> but at the time they’re being used.

Well, if you’re using the cookiestore for sessions, you don’t have to  
worry about stale sessions anyway. The file store should be avoided  
imo, the IO is simply too expensive. Database session storage is an  
option, although I see little to no reason to use it when you have  
something that just takes session storage away from the server.

Your database optimizations and operations can be run as a cron tab,  
just call a rake task that does what it needs to do and be done with it.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![mailtorajuit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed8c4c/32.png) [@mailtorajuit](https://www.ruby-forum.com/u/mailtorajuit)\
**Post date:** [April 27, 2010, 5:47pm UTC](https://www.ruby-forum.com/t/sessions/187592/3 "2010-04-27T17:47:19Z")

</div>

> in my application, i have login form. while login into the application  
> iam maintaning the details in session. i want to remove the stale  
> sessions and while removing the stale sessions i want to perform some  
> operattions on database . how to do this.

How are the sessions stored? The default now is Cookie store, so you  
can’t  
easily delete all sessions. If you’re using file store, you can just  
remove  
all files in the folder, if your using a DB store you can truncate the  
table.

The other way is to have a version field checked/set in a filter in your  
application and empty any incoming session requests if they don’t have  
the  
right version. It won’t delete them all immediately, but at the time  
they’re being used.

Cheers,

Andy

---

<div class="post-metadata">

**Author:** ![mailtorajuit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed8c4c/32.png) [@mailtorajuit](https://www.ruby-forum.com/u/mailtorajuit)\
**Post date:** [April 27, 2010, 6:43pm UTC](https://www.ruby-forum.com/t/sessions/187592/4 "2010-04-27T18:43:32Z")

</div>

On 27 Apr 2010, at 18:13, Hassan S. wrote:

> > Well, if you’re using the cookiestore for sessions, you don’t have  
> > to worry  
> > about stale sessions anyway.
> 
> ? How so?

Because the session data is kept in a cookie on the client side, not  
on the server in any way. The session is removed on the user’s  
computer when he quits his browser. As long as you’re not storing more  
than 4KB of (sensitive) data in the session (which you should never do  
in the first place), it’s the least expensive session storage with the  
least redundant data hanging around.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![mailtorajuit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed8c4c/32.png) [@mailtorajuit](https://www.ruby-forum.com/u/mailtorajuit)\
**Post date:** [April 27, 2010, 6:52pm UTC](https://www.ruby-forum.com/t/sessions/187592/5 "2010-04-27T18:52:19Z")

</div>

On Tue, Apr 27, 2010 at 9:38 AM, Peter De Berdt  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Well, if you’re using the cookiestore for sessions, you don’t have to worry  
> about stale sessions anyway.
> 
> ? How so?
> 
> Because the session data is kept in a cookie on the client side, not on the  
> server in any way. The session is removed on the user’s computer when he  
> quits his browser.

That’s irrelevant if the app in question depends on inactive sessions  
being expired.

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![mailtorajuit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed8c4c/32.png) [@mailtorajuit](https://www.ruby-forum.com/u/mailtorajuit)\
**Post date:** [April 27, 2010, 6:15pm UTC](https://www.ruby-forum.com/t/sessions/187592/6 "2010-04-27T18:15:25Z")

</div>

On Tue, Apr 27, 2010 at 8:56 AM, Peter De Berdt  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Well, if you’re using the cookiestore for sessions, you don’t have to worry  
> about stale sessions anyway.

? How so?

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![mailtorajuit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed8c4c/32.png) [@mailtorajuit](https://www.ruby-forum.com/u/mailtorajuit)\
**Post date:** [April 27, 2010, 7:01pm UTC](https://www.ruby-forum.com/t/sessions/187592/7 "2010-04-27T19:01:42Z")

</div>

On 27 Apr 2010, at 18:50, Hassan S. wrote:

> > quits his browser.
> 
> That’s irrelevant if the app in question depends on inactive sessions  
> being expired.

[http://dev.rubyonrails.org/ticket/10751](http://dev.rubyonrails.org/ticket/10751)

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![mailtorajuit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed8c4c/32.png) [@mailtorajuit](https://www.ruby-forum.com/u/mailtorajuit)\
**Post date:** [April 27, 2010, 7:33pm UTC](https://www.ruby-forum.com/t/sessions/187592/8 "2010-04-27T19:33:55Z")

</div>

On Tue, Apr 27, 2010 at 9:56 AM, Peter De Berdt  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> That’s irrelevant if the app in question depends on inactive sessions  
> being expired.
> 
> [http://dev.rubyonrails.org/ticket/10751](http://dev.rubyonrails.org/ticket/10751)

Interesting but also irrelevant; recognizing a request for an expired  
session is not the same as explicitly expiring a session and doing  
any necessary cleanup.

But thanks for the reference.

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan
