RavenDB as a session provider

118 views
Skip to first unread message

DanPlaskon

unread,
Jul 12, 2010, 7:19:23 AM7/12/10
to ravendb
I'm currently making use of the Memcached providers (http://
memcachedproviders.codeplex.com/) for managing session state in an
ASP.NET MVC application. It makes use of a database (currently SQL
Server in our implementation) as a fallback storage container for the
session state. Is this a viable use case for Raven? If so, how would
one implement a service to expire "stale" sessions?

theouteredge

unread,
Jul 12, 2010, 8:34:09 AM7/12/10
to ravendb
Could you expire session states by using a trigger?
http://ravendb.net/documentation/docs-server-triggers

And run a clean up operation deleting all expired sessions

DanPlaskon

unread,
Jul 12, 2010, 8:37:04 AM7/12/10
to ravendb
That seems like a viable option for expiring, thanks!

More generally though, is this a *good* idea? Is RavenDB recommended
for this sort of usage, or am I better served by sticking with SQL
Server for this sort of thing?

On Jul 12, 8:34 am, theouteredge <a...@theouteredge.co.uk> wrote:
> Could you expire session states by using a trigger?http://ravendb.net/documentation/docs-server-triggers
> > one implement a service to expire "stale" sessions?- Hide quoted text -
>
> - Show quoted text -

Ayende Rahien

unread,
Jul 12, 2010, 11:45:11 AM7/12/10
to ravendb
Yes, it is a good use for Raven.
If you want to expire stale session, you can define a background process that would run every X time and remove old sessions.

DanPlaskon

unread,
Jul 12, 2010, 11:55:07 AM7/12/10
to ravendb
Ayende,

Could you provide some guidance on how I should be locating the
expired sessions? Is this something I'd want to use an index for?

Chris Marisic

unread,
Jul 12, 2010, 5:42:16 PM7/12/10
to ravendb
While I'm somewhat of a novice and hope someone will correct me if I'm
mistaken but with that caveat said...

Anything you actively search for is what you want to create an index
for, I've frequently seen indexes in NoSQL stores called Materialized
Views that an index is really almost more of a stored procedure than
index in the sense of a Sql database.

So you would just put a property on your object that is like CreatedAt
and then you would get all of your objects that are CreatedAt >
sometime timeframe and you can scavenge across that.

DanPlaskon

unread,
Jul 13, 2010, 7:42:06 AM7/13/10
to ravendb
Sorry...I guess I should have been more clear. Is there a way to
delete all of the expired sessions without explicitly loading them and
deleting one-by-one? Something along the lines of "delete from Session
where expiredDate >= GETDATE()"?
> > > - Show quoted text -- Hide quoted text -

Ryan Heath

unread,
Jul 13, 2010, 8:00:01 AM7/13/10
to rav...@googlegroups.com
I think you want what Chris described but as a background task
suggested by Ayende.
This task runs on the server and is transparent to the clients.
http://ravendb.net/documentation/triggers/long-running

You may also want to add a AllowRead trigger to let Raven disallow
loading of expired sessions.
http://ravendb.net/documentation/triggers/read

// Ryan

DanPlaskon

unread,
Jul 13, 2010, 11:47:16 AM7/13/10
to ravendb
Ryan,

Great suggestions - thanks!

On Jul 13, 8:00 am, Ryan Heath <ryan.q.he...@gmail.com> wrote:
> I think you want what Chris described but as a background task
> suggested by Ayende.
> This task runs on the server and is transparent to the clients.http://ravendb.net/documentation/triggers/long-running
>
> You may also want to add a AllowRead trigger to let Raven disallow
> loading of expired sessions.http://ravendb.net/documentation/triggers/read

Ayende Rahien

unread,
Sep 21, 2010, 2:34:46 PM9/21/10
to rav...@googlegroups.com
Just an update, I just pushed the expiration bundle. Should be easiest way to deal with removing document based on time.

DanPlaskon

unread,
Oct 14, 2010, 7:40:06 PM10/14/10
to ravendb
Ayende,

Outstanding..thanks for the update on this!

I have another (somewhat related) question....

How would one go about creating a process by which an entity was
immediately deleted after being fetched from RavenDB? Picture a
persistent cache that did a "burn after read" type of operation.

Ayende Rahien

unread,
Oct 14, 2010, 9:01:25 PM10/14/10
to rav...@googlegroups.com
Implement a Read Trigger that did that 

DanPlaskon

unread,
Oct 15, 2010, 2:31:35 PM10/15/10
to ravendb
Just got this up and running....GREAT work here, Ayende

This makes Raven a great solution for temporary file/blog storage in a
clustered environment (eg. temporarily holding user-uploaded files,
asp.net sessions, the works) - thanks so much for adding this!
Reply all
Reply to author
Forward
0 new messages