简体   繁体   English

有什么方法可以使用外部进程(即不通过页面的后台代码)来缓存对象?

[英]Any way to cache an object using an outside process (i.e. not through a page's code-behind)?

I've got my first batch of really massive data that I need for my ASP.NET web application. 我已经有了我的ASP.NET Web应用程序所需的第一批真正的海量数据。 Up until now (for two years in fact!) nothing has come up that was so costly that I couldn't just do it on Page_Load or store it in ViewState or Session. 到现在为止(实际上已经有两年了!),没有任何事情如此昂贵,以至于我不能只在Page_Load上完成它或将其存储在ViewState或Session中。 But now, I need a list of objects that remains fairly static (gets updated once a day at most) and contains about 5000 objects, and building it every time on Page_Load causes the load time to take an obvious hit. 但是现在,我需要一个对象列表,该对象保持相当静态(最多每天更新一次),并包含约5000个对象,并且每次在Page_Load上对其进行构建都会导致加载时间受到明显影响。

Some Googling regarding caching shows some very elementary examples using stuff like Cache["myStuff"] = myObject; 关于缓存的一些Google搜索显示了一些非常基本的示例,例如使用Cache["myStuff"] = myObject; and that's all well and good. 一切都很好。 But I'd like to know if there is some way I can set my Web Application to run an update at a specific time, regardless of whether or not the application is being accessed or in use. 但是我想知道是否可以通过某种方式将Web应用程序设置为在特定时间运行更新,而不管是否正在访问或使用该应用程序。

For example, I want this process to update the list to run once a day at like 4:00am when no one is using anything. 例如,我希望此过程可以将列表更新为每天凌晨4:00运行一次,而此时没人使用任何东西。 So let's say on day 1 in the afternoon, the Page_Load checks to grab the cached object, but it comes back null, so in that case, bite the bullet and request/build the list for the rest of day 1, store it in cache. 因此,假设在下午的第1天,Page_Load检查以获取缓存的对象,但是它返回null,因此,在这种情况下,请咬紧牙关,并请求/构建第1天其余时间的列表,并将其存储在缓存中。 Throughout the rest of day 1, no one has to build the object because it's in cache and it's still valid. 在第一天的剩余时间里,没有人需要构建对象,因为它位于缓存中并且仍然有效。

Day 1 ends, and it's now 4:00am on day 2. No one is using any pages. 第1天结束,现在是第2天凌晨4:00。没有人使用任何页面。 I want the object that was stored in cache from day 1 to be deleted and re-built, so that when people get to the office in the morning, the first person who accesses the page doesn't need to build the list for today, it's already done. 我希望删除从第一天开始存储在缓存中的对象,以便人们在早上到达办公室时,第一个访问该页面的人今天不需要构建该列表,已经完成了。

The only idea I have would be to look into creating a console application that runs on a Windows scheduled task or something. 我唯一的想法是研究创建一个可在Windows预定任务等上运行的控制台应用程序。 But even then, I'm not sure how I would be able to interact with the ASP.NET web application from an external application like that. 但是即使那样,我仍然不确定如何从这样的外部应用程序与ASP.NET Web应用程序进行交互。

Hopefully I'm making sense. 希望我有道理。 Is what I'd like to accomplish even possible? 我想实现的目标甚至有可能吗?

If you use a distributed cache like MemCached, you could create a Windows Service or Console application for populating the cache. 如果使用像MemCached这样的分布式缓存,则可以创建Windows服务或控制台应用程序以填充缓存。 Since both applications (The service and the web app) will use the same cache, it will solve your problem. 由于两个应用程序(服务和Web应用程序)将使用相同的缓存,因此可以解决您的问题。

Another solution is to have a page just for that (ie /startcache.aspx) that will do the cachin on page_load. 另一个解决方案是为此设置一个页面(即/startcache.aspx),该页面将在page_load上执行cachin。 And you can schedule a request to that page. 您可以安排对该页面的请求。 You could also hide the page from outside the web-app using some kind of firewall (so nobody accesses that page!). 您还可以使用某种防火墙从Web应用程序外部隐藏页面(因此,没有人可以访问该页面!)。 Finally, the good part of this solution is that you can reuse your current code, as it will work in the same project. 最后,该解决方案的优点是您可以重用当前代码,因为它将在同一项目中工作。

Hope it helps. 希望能帮助到你。

Redis是进程外第三方缓存/键值存储区之外的另一种选择。

To reduce load on the server and backend and serving all daily data (as I understand from the question) 为了减少服务器和后端的负载并提供所有每日数据(据我从问题中了解)

Why not create a data file (CSV,XML,JSON) and offer that as a data-point. 为什么不创建数据文件(CSV,XML,JSON)并将其作为数据点提供。

From your question it seems that the client(application) is capable of running their own queries against that dataset. 从您的问题看来,客户端(应用程序)能够针对该数据集运行自己的查询。

Creating a file like that can be done on a fixed time set, saved and as such just one time. 创建这样的文件可以在固定的时间集上完成,然后保存一次即可。 No need to include thirt-party solutions (besides their respectable qualities) 无需包括第三方方的解决方案(除了其值得尊敬的品质)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过代码隐藏使复选框创建TemplateField? - How Do I Make a TemplateField with Checkbox Through Code-behind? 使用jQuery AJAX在控制代码隐藏而不是页面代码隐藏中调用ASP.NET函数 - Using jQuery AJAX to call ASP.NET function in control code-behind instead of page code-behind 代码隐藏页面无法“查看”aspx页面中声明的任何项目/控件 - Code-behind page cannot “see” any items/controls declared in the aspx page 将在代码背后创建的对象注入到ViewModel中 - Inject object created in code-behind to ViewModel {Binding}的等效代码背后是什么? - What's the code-behind equivalent of {Binding}? 如何在代码外定义AutoMapper映射,即在XML文件中或使用不同的方法进行完全可配置的对象映射? - How to define AutoMapper mapping outside code i.e. in a XML file or use different approach for a fully configurable object mapping? 使用Ajax调用代码隐藏函数? - Using Ajax to call code-behind function? 在 CefSharp C# 中加载 html 页面后,是否有可能获得状态代码,即 (200,301,302)? - Is there any possibility to get status code i.e. (200,301,302) after loading html page in CefSharp C#? 翻译DataGrid MouseEvent,以便在View的Code-Behind中没有代码 - Translate DataGrid MouseEvent so I do not have code in View's Code-Behind 为什么我不能在视图的演示者背后的视图代码中调用方法? - Why can't I call a method in my View's code-behind from the view's presenter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM