在服务器中为所有用户C#缓存我的静态数据 [英] Cache my static data in server for all user C#

查看:209
本文介绍了在服务器中为所有用户C#缓存我的静态数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想在服务器中缓存一些静态数据。如果任何用户请求相同的数据缓存应该返回。



如果我使用HttpContext.cache,它将因用户而异。请帮我在c#中如何做到这一点?



我尝试过:



HttpContext.Cache.Insert(cacheKey,Sonarresult,null,DateTime.Now.AddSeconds(Timeduration),Cache.NoSlidingExpiration);我试过这个但是对于所有用户都将存储到缓存中。我不想要那个。第一个用户只需要存储它。

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.

推荐答案

最可靠的方法是将数据存储在数据库中,并始终从那里访问它。这样,无论运行哪个Web服务器,所有用户都可以获得相同的数据。
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.


这篇关于在服务器中为所有用户C#缓存我的静态数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆