简体   繁体   中英

ASP.net session how to set some object to expire earlier

I set session to be 24h.

I would like that one object, ie Session["Table1"] to expire after 20 minutes, because it's too big.

Can I manage just that one object to be different?

Thanks

Cache has expiration capabilities. Unlike session, it is shared by all users accessing the web application (per process). Depending on your needs, this may be a good or a bad thing.

An alternative is to store a user-specific cache key in session, and have that key point to an item in the cache that expires sooner than the session.

Consider

  • A 24 hour session is long, perhaps too long.
  • Minimize the amount of data you read from session (serialization penalty for out of process access).
  • Use read-only session when possible (avoids lock contention between closely-timed requests from the same user).
  • SQL Server (and most databases) have extremely efficient caching mechanisms for frequently accessed data. Before you start storing whole tables in memory, be sure you actually need to do so.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM