Scottingham
Scottingham

Reputation: 946

Can you combine the best of inProc and Session State?

Is there a way to use the IIS inProc scheme for 95% of the time, while maintaining and updating the Session State variable?

Ideally I'd it if in the off chance there is an app-pool recycle it would refresh the inProc data from the Session State service.

There is about a 200msec difference between using InProc and Session State, so if this is at all possible it would really speed up the program. Otherwise, stability concerns leave me forced to use Session State.

Upvotes: 1

Views: 168

Answers (2)

Scottingham
Scottingham

Reputation: 946

The solution I ended up using was using the HttpContextBase which has a cache section.

This caches in the app pool's memory. It is accessible to all users, which is actually perfect for my application.

Example:

HttpContextBase httpContext;
      CacheObject  NCO = (CacheObject)httpContext.Cache["CacheName"];

Upvotes: 0

Lucas Trzesniewski
Lucas Trzesniewski

Reputation: 51430

If I understand correctly, you want to use InProc most of the time, and StateServer sometimes. As you're saying "95% of the time", that looks like you need something custom.

So perhaps you should implement a session state store provider. You can use the InProc mode source code as a starting point. You also have the source code of the StateServer provider here.

The problem with this approach is that both of these classes are internal sealed so you cannot really access them easily. You could reuse their source code, or call them with reflection, or generate a method using expression lambdas... I don't think there's a perfect solution there.

Another solution would be to rebuild a session state store from scratch that fits your needs 100%, but that'd be more complicated and error-prone.

Upvotes: 1

Related Questions