IIS can recycle your application pool (for several reasons, including idling and no requests, too much memory use, etc...) At that point your application will be unloaded, and then loaded again later. Hence your cache values are gone.
Second, do you have any code that at some point prunes and removes old entries from cache? If not, it means you got a memory leak as it'll continue to grow indefinitely (and thereby trigger application pool recycle).
If you do have prunning code (so the cache is actively managed to avoid indefinite growth), and you need its contents to survive past pool restarts, then you have few options:
- Use database. Simply have a table of active users and add/delete there.
- Pro: survives even unexpected crashes of app, iis, and even machine itself.
- Con: Slow due to db access and db contention point possibilities.
- Put code in your application start / end event handlers to serialize contents to a file on end, and deserialize on start.
- Pro: faster than db. works during graceful shutdowns.
- Con: will not work due to unexpected crash.