1

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!

1 Answer 1

4

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 );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.