Comments (7)
Session is always backed by an IDistributedCache
implementation. IMemoryCache
is a different interface completely. Are you asking if you can use 2 implementations of session within the same app or are you asking if you can configure session to use the SQL implementation of IDistributedCache
and also use IMemoryCache
for other things?
If it's the latter, then yes, because those are 2 different interfaces that becomes trivial.
from session.
Sounds like he wants IDistributedCache for session and IMemoryCache for other stuff. Yes, that's just fine. Go look at the cache repo samples.
from session.
Right, so the sample at https://github.com/aspnet/Session/blob/dev/samples/SessionSample/Startup.cs says to do something like this:
// Uncomment the following line to use the Microsoft SQL Server implementation of IDistributedCache.
// Note that this would require setting up the session state database.
//services.AddSqlServerCache(o =>
//{
// o.ConnectionString = "Server=.;Database=ASPNET5SessionState;Trusted_Connection=True;";
// o.SchemaName = "dbo";
// o.TableName = "Sessions";
//});
I'm probably completely misinterpreting this, but to me that implies that in order to have SQL backed sessions, I need to change caching to also use a SQL store.
I I have all three:
services.AddSqlServerCache(); // add SQL backed implementation of IDistributedCache ?
services.AddCaching(); // add IMemoryCache,IDistributedCache for general in-proc caching?
services.AddSession();
The sample implies that without line 1 AddSqlServerCache(), the call to AddSession() results in the use of the IMemoryCache added from the call to AddCaching()?
How does AddSession know to use the SQL IDistributedCache instead of the IMemoryCache?
Am I just completely confused about how any of this works? LOL!
from session.
Session always uses IDistributedCache
https://github.com/aspnet/Session/blob/dev/src/Microsoft.AspNet.Session/SessionServiceCollectionExtensions.cs#L27
https://github.com/aspnet/Session/blob/dev/src/Microsoft.AspNet.Session/DistributedSessionStore.cs#L16
AddCaching adds a IDistributedCache implemented using IMemoryCache:
https://github.com/aspnet/Caching/blob/dev/src/Microsoft.Extensions.Caching.Memory/MemoryCacheServicesExtensions.cs#L23
If you replace that IDistributedCache registration with AddSqlServerCache then you use SQL distributed cache, but IMemoryCache is still registered as a seperate service.
from session.
Oh, I see. So the order in which I register them is key to making this work? Specifically, for my scenario it needs to be:
AddCaching(); // Add IMemoryCache and IDistributedCache
AddSqlServerCache(); // overwrite IDistributedCache registration from AddCaching with SQL backing
AddSession(); // which will now resolve to using SQL backed IDistributedCache
Is that about right?
from session.
Yes, that should work.
from session.
Phew! Thank for your time! I appreciate the help.
As a side note, it would be cool if the "AddServiceX" extension methods had some easy way to see what services they register without having to find the source (maybe in the method comments).
from session.
Related Issues (20)
- Remove obsolete options APIs HOT 3
- Update session to configure DistributedMemoryCache options by default HOT 3
- Add logging scope for session HOT 2
- Random "Accessing expired session" warning HOT 4
- Error closing the session with .net 2.1.0-preview1 HOT 12
- Any plans for maximum session size property? HOT 2
- [1.1.4] Flaky test: SessionTests.SessionLogsCacheRefreshException HOT 6
- System.OperationCanceledException at Microsoft.Extensions.Caching.Redis.RedisCache+<RefreshAsync>d__25.MoveNext HOT 4
- cant access Session in other API HOT 5
- Error closing the session HOT 1
- [Patch 2.0.x] Downgrade cancellation logs HOT 1
- Add EventSource/EventCounter tracing and metrics for Session HOT 1
- Session does not work with Redis when the client has HTTP keep-alives disabled HOT 6
- Session cannot be re-loaded HOT 8
- Determine if the session cookie is considered essential HOT 1
- THIS ISSUE TRACKER IS CLOSED - use the Home repo issue tracker
- Session OnStart and Session OnEnd HOT 8
- How to get number of session HOT 3
- Re-initialize Session middleware from controller HOT 2
- How to add a custom session in .net core? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from session.