# Newbie Session Discussion: Expiration and Clean Up NO CRONS

**URL:** <https://www.ruby-forum.com/t/newbie-session-discussion-expiration-and-clean-up-no-crons/131839>\
**Category:** Rails\
**Created:** [March 13, 2008, 6:42pm UTC](https://www.ruby-forum.com/t/newbie-session-discussion-expiration-and-clean-up-no-crons/131839 "2008-03-13T18:42:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Baz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c4cdca/32.png) [@Baz](https://www.ruby-forum.com/u/Baz)\
**Post date:** [March 13, 2008, 6:42pm UTC](https://www.ruby-forum.com/t/newbie-session-discussion-expiration-and-clean-up-no-crons/131839/1 "2008-03-13T18:42:59Z")

</div>

Please forgive this discussion, but I’m not sure where to find what I’m  
looking for.

I’m coming for a PHP background, where I’ve only ever used sessions for  
very  
simple storage (serializing when I need a lil’ more structure). Also  
I’ve  
been using the PHP sessions, which PHP is responsible for cleaning up.

After reading Agile Web D. Development, they made some  
suggestions:

- Don’t store data in the session, but have a separate structure that  
you reference with the session ID
- Store sessions in the database.

This poses some questions:

- Can you implement some sort of session cleaning solely through Ruby  
without the need for a CRON job?
- With this clean up (or even with a cron job) how does one handle  
the  
associated data in the database? How do we prevent these from being  
orphaned, since their session is now gone. Eg. in the book, I think  
they  
were talking about cart information. If you had each cart stored in  
the  
database and referenced by a session id, how do we ensure that that  
cart  
gets deleted when the user’s session expires or is cleaned?
- How does Rails 2.0 and the default Cookie based session storage  
help/hurt the above? I take it there’s no cleanup? Still, how do we  
clean  
the associated data?

Any help would be much appreciated.  
Please bare with the ignorance.

## ThanX in advance guys.

Baz L  
Web D. 2.0

> **[Web Development 2.0: Web Design, ASP.NET Core, CakePHP, Javascript](https://www.webdevelopment2.com/)**
>
> Quick and Dirty Web Development

---

<div class="post-metadata">

**Author:** ![Baz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c4cdca/32.png) [@Baz](https://www.ruby-forum.com/u/Baz)\
**Post date:** [March 14, 2008, 10:22pm UTC](https://www.ruby-forum.com/t/newbie-session-discussion-expiration-and-clean-up-no-crons/131839/2 "2008-03-14T22:22:55Z")

</div>

Please forgive this discussion, but I’m not sure where to find what I’m  
looking for.

I’m coming for a PHP background, where I’ve only ever used sessions for  
very  
simple storage (serializing when I need a lil’ more structure). Also  
I’ve  
been using the PHP sessions, which PHP is responsible for cleaning up.

After reading Agile Web D. Development, they made some  
suggestions:

- Don’t store data in the session, but have a separate structure that  
you reference with the session ID
- Store sessions in the database.

This poses some questions:

- Can you implement some sort of session cleaning solely through Ruby  
without the need for a CRON job?
- With this clean up (or even with a cron job) how does one handle  
the  
associated data in the database? How do we prevent these from being  
orphaned, since their session is now gone. Eg. in the book, I think  
they  
were talking about cart information. If you had each cart stored in  
the  
database and referenced by a session id, how do we ensure that that  
cart  
gets deleted when the user’s session expires or is cleaned?
- How does Rails 2.0 and the default Cookie based session storage  
help/hurt the above? I take it there’s no cleanup? Still, how do we  
clean  
the associated data?

Any help would be much appreciated.  
Please bare with the ignorance.

## ThanX in advance guys.

Baz L  
Web D. 2.0  
[http://WebDevelopment2.com/](http://WebDevelopment2.com/) [http://webdevelopment2.com/](http://webdevelopment2.com/)
