Click here to Skip to main content
16,016,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to cache some static data in server. if any user request for same data cache should return that.

if i go with HttpContext.cache, it will vary by user. please help me how to do that in c#?

What I have tried:

HttpContext.Cache.Insert(cacheKey, Sonarresult, null, DateTime.Now.AddSeconds(Timeduration), Cache.NoSlidingExpiration); i tried this but for all users will store into cache. i dont want that. first user only has to store it.
Posted
Updated 19-Sep-16 21:32pm
Comments
Garth J Lancaster 20-Sep-16 3:01am    
surely you need to put your own management 'context' over HttpContext.cache

a) check if the data exists in the cache
b) if the data is in the cache from (a), then the 'first' user must have put it there
c) if the data is not in the cache from (a), you are the 'first user', store the data in the cache

1 solution

The most reliable way is to store the data in a DB, and always access it from there. That way, all users are guaranteed to get the same data regardless of which web server they are running on.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900