Comments (4)
There are some known issues with MemoryCache (and DistributedMemoryCache) over-eagerly removing items due to perceived memory load. See CompactOnMemoryPressure: https://github.com/aspnet/Caching/blob/d417a71d7be76a629336227f3bb75d46bc6cf9a3/src/Microsoft.Extensions.Caching.Memory/MemoryCacheOptions.cs#L21
This has been redesigned for 2.0 RTM
from session.
Thank you for the information.
In the meantime we may have found a workaround for v1.1.2.
When having the services declared in this order we constantly lose the session:
services.AddMvc();
services.AddDistributedMemoryCache();
services.AddSession(o => o.IdleTimeout = TimeSpan.FromMinutes(20);
As soon as we invert the lines the problem disappears:
services.AddDistributedMemoryCache();
services.AddSession(o => o.IdleTimeout = TimeSpan.FromMinutes(20);
services.AddMvc();
This workaround is actually working, we have tried inverting multiple times the lines of code on multiple PCs and whenever we add Mvc after MemoryCache and Session we are never been able to get the "Accessing expired session" warning.
I thought only the Configure
method needed to have each IApplicationBuilder
defined in order, while adding IServiceCollection
in the ConfigureServices
method did not have that requirement.
Am I wrong? Does this make sense to you?
from session.
Service registration order can matter if multiple things try to register the same service differently. These differences may explain what you're seeing:
https://github.com/aspnet/Mvc/blob/rel/1.1.3/src/Microsoft.AspNetCore.Mvc.TagHelpers/DependencyInjection/TagHelperExtensions.cs#L34-L35
https://github.com/aspnet/Caching/blob/rel/1.1.2/src/Microsoft.Extensions.Caching.Memory/MemoryCacheServiceCollectionExtensions.cs#L83
The MVC registration uses a shared MemoryCache and shared MemoryCacheOptions. The Caching one uses an isolated MemoryCache and options. Sharing the cache may be worse for you if something else is putting a lot of load on it.
from session.
Thank you @Tratcher for your clarification!
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
- 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.