I'm using the default session state provider and store session on SQL Server inside the DB of my application. Everything works fine.
Now I'm wondering how to add a "cache layer" above the standard session provider to have session cached with low priority (just in case I have spare cache) and leave the SQL Server storage as a fallback if session are not in the cache.
Of course I know cache is application wide and sessions are private to user but storing and retrieving from cache with session Ids easily resolve the issue. Now since I'm fairly new to asp.net I don't know how to implement the code that first checks in the
cache (and the one that always saves both to the cache and the db) on top of the default provider, without having to write a custom session provider. Or if I'm forced to write a custom provider, what is the easiest way to have it behave like the sandard session
provider set with SQL Server storage with this cache layer on top?
the way they suggest is very similar only with a custom "persistent session on db", disabling sessions and emulating them when needed.
By the way I still want to keep sessions for compatibility with third party software that I may add in future (forums, chats,) to my home-made cms.
Having it in SQL Server is ok even if I don't write custom tables and call them only when needed (I implemented this behaviour in my old classic asp framework disablind sessions). Now the point is that to alleviate the burden of 2 db query for each page
load (1 for reading session data and 1 for writing) stuffing some sessions in the cache when it's free and having the db as a fallback in my opinion would be really good.
Just have to find a way to implement it in a easy way since I'm really new (noob) with .net
So to more directly answer your question, I think you'd need to implement your own SessionStateProviderBase-derived class to perform this caching. You could then aggregate the real SqlServerSessionProvider and delegate to it as needed. Feels like a lot of
work for something you shouldn't be using anyway :)
Once I do the job I would use it anyway :) By the way I had thi sad feeling I had to implement the whole stuff... maybe with the new Universal Providers inheriting from session provider is easier... I mean "hooking" to the default sql behaviour and overriding
only the methods you need to set and get the session should be easier... Actually implementing the session provider is (not the universal one wich is "new") seems quite a nightmare! :)
The only thing I don't like about the new provider is that in a post I read it seems it clears db expired session on each call (to avoid using a job and making it useful on SQL Azure) and this seems to cause "locking/concurrency" issue... but maybe this
behaviour in the new provider could be ovverriden as well.. the bad thing is that I can't seem to find any documentation yet to implement a custom session provider based on the new universal provider.
You can check the "new" providers
here on Scott Hanselman blog and it seems the session one now is more "aligned" with the other ones.
You can check the "new" providers
here on Scott Hanselman blog and it seems the session one now is more "aligned" with the other ones.
Well, as you tell from my blog post I never use Session. Also, I personally feel most of the provider model is not usable so I never use MembershipProvider or RoleProvider, so I never have these problems (just different ones, but I prefer those). :)
I understand very well... When I first approached asp.net (wich happened just a bunch of months ago) I thought that everything was ready just have to configure it in the web.config. Then I realized that for more performant and tailored scenarios you'd better
do most of the stuff yourself.
The only thing that's sort of "blocking" me from going to far from the "default" stuff, as I explained, is the will to keep compatibility and the hope for an always renewed support and enanchment from MS.
manighht
0 Points
10 Posts
Cache wrapper for SQL Server session storage
Apr 26, 2012 05:30 PM|LINK
Hallo,
I'm using the default session state provider and store session on SQL Server inside the DB of my application. Everything works fine.
Now I'm wondering how to add a "cache layer" above the standard session provider to have session cached with low priority (just in case I have spare cache) and leave the SQL Server storage as a fallback if session are not in the cache.
Of course I know cache is application wide and sessions are private to user but storing and retrieving from cache with session Ids easily resolve the issue. Now since I'm fairly new to asp.net I don't know how to implement the code that first checks in the cache (and the one that always saves both to the cache and the db) on top of the default provider, without having to write a custom session provider. Or if I'm forced to write a custom provider, what is the easiest way to have it behave like the sandard session provider set with SQL Server storage with this cache layer on top?
Thanks for any suggestions
BrockAllen
All-Star
27438 Points
4893 Posts
MVP
Re: Cache wrapper for SQL Server session storage
Apr 26, 2012 05:34 PM|LINK
Not that this directly answers your question, but here are some thoughts about Session and Caching.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
manighht
0 Points
10 Posts
Re: Cache wrapper for SQL Server session storage
Apr 26, 2012 08:22 PM|LINK
Thank you BrockAllen,
the way they suggest is very similar only with a custom "persistent session on db", disabling sessions and emulating them when needed.
By the way I still want to keep sessions for compatibility with third party software that I may add in future (forums, chats,) to my home-made cms.
Having it in SQL Server is ok even if I don't write custom tables and call them only when needed (I implemented this behaviour in my old classic asp framework disablind sessions). Now the point is that to alleviate the burden of 2 db query for each page load (1 for reading session data and 1 for writing) stuffing some sessions in the cache when it's free and having the db as a fallback in my opinion would be really good.
Just have to find a way to implement it in a easy way since I'm really new (noob) with .net
BrockAllen
All-Star
27438 Points
4893 Posts
MVP
Re: Cache wrapper for SQL Server session storage
Apr 26, 2012 09:18 PM|LINK
So to more directly answer your question, I think you'd need to implement your own SessionStateProviderBase-derived class to perform this caching. You could then aggregate the real SqlServerSessionProvider and delegate to it as needed. Feels like a lot of work for something you shouldn't be using anyway :)
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
manighht
0 Points
10 Posts
Re: Cache wrapper for SQL Server session storage
Apr 26, 2012 10:17 PM|LINK
Once I do the job I would use it anyway :) By the way I had thi sad feeling I had to implement the whole stuff... maybe with the new Universal Providers inheriting from session provider is easier... I mean "hooking" to the default sql behaviour and overriding only the methods you need to set and get the session should be easier... Actually implementing the session provider is (not the universal one wich is "new") seems quite a nightmare! :)
The only thing I don't like about the new provider is that in a post I read it seems it clears db expired session on each call (to avoid using a job and making it useful on SQL Azure) and this seems to cause "locking/concurrency" issue... but maybe this behaviour in the new provider could be ovverriden as well.. the bad thing is that I can't seem to find any documentation yet to implement a custom session provider based on the new universal provider.
You can check the "new" providers here on Scott Hanselman blog and it seems the session one now is more "aligned" with the other ones.
BrockAllen
All-Star
27438 Points
4893 Posts
MVP
Re: Cache wrapper for SQL Server session storage
Apr 26, 2012 10:47 PM|LINK
Well, as you tell from my blog post I never use Session. Also, I personally feel most of the provider model is not usable so I never use MembershipProvider or RoleProvider, so I never have these problems (just different ones, but I prefer those). :)
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
manighht
0 Points
10 Posts
Re: Cache wrapper for SQL Server session storage
Apr 27, 2012 01:54 PM|LINK
I understand very well... When I first approached asp.net (wich happened just a bunch of months ago) I thought that everything was ready just have to configure it in the web.config. Then I realized that for more performant and tailored scenarios you'd better do most of the stuff yourself.
The only thing that's sort of "blocking" me from going to far from the "default" stuff, as I explained, is the will to keep compatibility and the hope for an always renewed support and enanchment from MS.
Btw thanks so far for the talk ;)