Reputation: 8618
I want to share a Queue data structure between all the users of my web application, without using any database. I want this data to be always available and thread safe between all the users. Is caching a good idea? I tried using System.Web.Caching by calling:
Queue<int> users= new Queue<int>();
Context.Cache.Insert("users", users, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration);
in my Global.axax file, but when I call the cache in my .cs files:
( (Queue<int>) Cache["users"] ).Enqueue( newUser);
I get the following error:
'System.Web.Caching.Cache' is a 'type' but is used like a 'variable'
Am I using caching correctly?
Thanks!
Upvotes: 1
Views: 586
Reputation: 532765
The Controller class doesn't have a Cache property like the ASP.NET web forms Page class. You need to reference it off the HttpContext property.
((Queue<int>)HttpContext.Cache["users"]).Enqueue( newUser );
Upvotes: 4