简体   繁体   English

ASP.NET中的简单缓存机制

[英]Simple caching mechanism in ASP.NET

I had asked a question on how to implement real time updates in ASP.NET and received a very explanatory and a helpful answer from "jdk" at: 我曾问过一个有关如何在ASP.NET中实现实时更新的问题,并且在以下位置从“ jdk”获得了非常解释性和有用的回答:

How to implement real time updates in ASP.NET 如何在ASP.NET中实施实时更新

I understand that memcached or .net caching application block can be used as the caching layer. 我知道memcached或.net缓存应用程序块可以用作缓存层。 Currently, I am looking for a very simple mechanism to implement this and do not have the resources for using memcached or the caching application block. 当前,我正在寻找一种非常简单的机制来实现此功能,并且没有使用memcached或缓存应用程序块的资源。

Can someone suggest a solution? 有人可以提出解决方案吗?

I am looking for a very simple mechanism to implement this and do not have the resources for using memcached or the caching application block. 我正在寻找一种非常简单的机制来实现此目的,并且没有使用memcached或缓存应用程序块的资源。

You can always store your data into Static fields. 您始终可以将数据存储到“静态”字段中。 This will be shared across all users and will be alive as long as the IIS is not reseted or stopped. 只要未重置或停止IIS,它将在所有用户之间共享并保持活动状态。

This book has great examples for building out an ASP.NET application using the MVP Design Pattern including a class for handling caching. 本书提供了使用MVP设计模式构建ASP.NET应用程序的出色示例,其中包括用于处理缓存的类。

ASP.NET 3.5 Social Networking: An Expert Guide to Building Enterprise-Ready Social Networking and Community Applications with ASP.NET 3.5 by Andrew Siemer ASP.NET 3.5社交网络:用ASP.NET 3.5构建企业就绪的社交网络和社区应用程序的专家指南,作者:Andrew Siemer

static (as Daok has suggested) or as HttpContext.Current.Application["key"] = value; 静态(如Daok所建议)或HttpContext.Current.Application["key"] = value; ; ; You wold have to remember the Type every time you "get" it 您每次都要“记住”类型时都要记住它

This will probably cost me some rep, but I've done it and it works: consider using a singleton to cache your data. 这可能会花费我一些代表,但是我已经做到了,并且可以正常工作:考虑使用单例来缓存数据。

Assuming you're looking for a global, read-only cache, and that you don't have a ton of data, you can simply have properties for each cachable element, and wrap the gets in a time check if you need to re-load the data. 假设您要查找的是全局只读缓存,并且没有大量数据,则可以简单地为每个可缓存元素拥有属性,并将获取的内容包装在时间中,以检查是否需要重新加载数据。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM