https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.page.cache?view=netframework-4.8

Gets the Cache object associated with the application in which the page resides.

An application's Cache object allows you to store and retrieve arbitrary data on subsequent requests. The cache is not specifically associated with a page or user session. It is used primarily to enhance application performance. For more information, see Caching Application Data. For more information on the difference between application caching and page output caching, see ASP.NET Caching Overview.

Page.Cache vs. HttpContext.Current.Cache

 

There is no difference, the former uses the current page instance and it's Cache property, the latter uses the static approach via HttpContext.Current.Cache which would work also in a static method without page instance.

Both are referring to the same application cache.

So you can get the Cache via Page, for example in Page_Load:

protected void Page_load(Object sender, EventArgs e)
{
System.Web.Caching.Cache cache = this.Cache;
}

or in a static method (which is used in a HttpContext) via HttpContext.Current:

static void Foo()
{
var context = HttpContext.Current;
if (context != null)
{
System.Web.Caching.Cache cache = context.Cache;
}
}

I find following detail from http://theengineroom.provoke.co.nz/archive/2007/04/27/caching-using-httpruntime-cache.aspx

For caching I looked into using HttpContext.Current.Cache but after reading other blogs I found that caching using HttpContext uses HttpRuntime.Cache to do the actual caching. The advantage of using HttpRuntime directly is that it is always available, for example, in Console applications and in Unit tests.

Using HttpRuntime.Cache is simple. Objects can be stored in the cache and are indexed by a string. Along with a key and the object to cache the other important parameter is the expiry time. This parameter sets the time before the object is dropped from the cache.

Here is good link for you.

Another good resource.

Is the HttpContext.Current.Cache available to all sessions

HttpContext.Current is available to all pages, but not necessarily to all threads. If you try to use it inside a background thread, ThreadPool delegate, async call (using an ASP.NET Async page), etc., you'll end up with a NullReferenceException.

If you need to get access to the cache from library classes, i.e. classes that don't have knowledge of the current request, you should use HttpRuntime.Cache instead. This is more reliable because it doesn't depend on an HttpContext.

扩展阅读

Cache Class

Caching Application Data

How to: Add Items to the Cache

You can access items in the application cache using the Cache object. You can add an item to the application cache using the Cache object's Insert method. The method adds an item to the cache and has several overloads that enable you to add the item with different options for setting dependencies, expiration, and removal notification. If you use the Insert method to add an item to the cache and an item with the same name already exists, the existing item in the cache is replaced.

You can also add items to the cache using the Add method. This method enables you to set all the same options as the Insert method; however, Add method returns the object you added to the cache. Additionally, if you use the Add method and an item with the same name already exists in the cache, the method will not replace the item and will not raise an exception.

How to: Retrieve Values of Cached Items

To retrieve data from the cache, you specify the key that the cached item was stored under. However, because information stored in the cache is volatile不稳定的—that is, it might be removed by ASP.NET—the recommended development pattern is to determine first whether the item is in the cache. If it is not, you add it back to the cache and then retrieve the item.

To retrieve the value of a cached item

  • Check to see if the item is not null (Nothing in Visual Basic), in the Cache object. If it exists, assign it to your variable. Otherwise, recreate the item, add it to the cache, and then access it.

    The following code example shows how to retrieve the item named CacheItem from the cache. The code assigns the contents of the item to the variable named cachedString. If the item is not in the cache, the code adds the item to the cache and then assigns the item to cachedString.

    C#
string cachedString;
cachedString = (string)Cache["CacheItem"];
if (cachedString == null)
{
cachedString = "Hello, World.";
Cache.Insert("CacheItem", cachedString);
}

Page.Cache的更多相关文章

  1. Page cache和Buffer cache[转1]

    http://www.cnblogs.com/mydomain/archive/2013/02/24/2924707.html Page cache实际上是针对文件系统的,是文件的缓存,在文件层面上的 ...

  2. page cache 与 page buffer 转

    page cache 与 page buffer 标签: cachebuffer磁盘treelinux脚本 2012-05-07 20:47 2905人阅读 评论(0) 收藏 举报  分类: 内核编程 ...

  3. 【转】Linux Page Cache的工作原理

    1 .前言 自从诞生以来,Linux 就被不断完善和普及,目前它已经成为主流通用操作系统之一,使用得非常广泛,它与Windows.UNIX 一起占据了操作系统领域几乎所有的市场份额.特别是在高性能计算 ...

  4. linux page cache和buffer cache

    主要区别是,buffer cache缓存元信息,page cache缓存文件数据 buffer 与 cache 是作为磁盘文件缓存(磁盘高速缓存disk cache)来使用,主要目的提高文件系统系性能 ...

  5. Page Cache buffer Cache

    https://www.thomas-krenn.com/en/wiki/Linux_Page_Cache_Basics References Jump up ↑ The Buffer Cache ( ...

  6. 工作于内存和文件之间的页缓存, Page Cache, the Affair Between Memory and Files

    原文作者:Gustavo Duarte 原文地址:http://duartes.org/gustavo/blog/post/what-your-computer-does-while-you-wait ...

  7. page cache和buffer cache

    因为要优化I/O性能,所以要理解一下这两个概念,这两个cache着实让我迷糊了好久,通过查资料大概明白了两者的区别,试着说下. page cache:文件系统层级的缓存,从磁盘里读取的内容是存储到这里 ...

  8. Page Cache, the Affair Between Memory and Files

    Previously we looked at how the kernel manages virtual memory for a user process, but files and I/O ...

  9. page cache 与free

    我们经常用free查看服务器的内存使用情况,而free中的输出却有些让人困惑,如下: 先看看各个数字的意义以及如何计算得到: free命令输出的第二行(Mem):这行分别显示了物理内存的总量(tota ...

  10. Page Cache与Page回写

    综述 Page cache是通过将磁盘中的数据缓存到内存中,从而减少磁盘I/O操作,从而提高性能.此外,还要确保在page cache中的数据更改时能够被同步到磁盘上,后者被称为page回写(page ...

随机推荐

  1. Redis在windows下安装与配置

    一.安装Redis 1. Redis官网下载地址:http://redis.io/download,下载相应版本的Redis,在运行中输入cmd,然后把目录指向解压的Redis目录. 2.启动服务命令 ...

  2. 兼容在安装linux系统过程中不支持非原装的光模块的命令

    1 .通过ifconfig -a发现有网卡找不到,并且配置没有问题,那么很可能是光模块有问题2 .dmesg | grep 82599EB ,通过这个命令过滤发现有如下信息: [ 7142.12197 ...

  3. iOS的签名机制

    1.从keychain里“从这证书颁发机构请求证书”,这样就在本地生成了一对公私钥,保存的CertificateSigningRequest就是公钥,私钥保存在本地电脑里. 2.苹果自己有一对固定的公 ...

  4. RN如何基于js代码手动打一个main.jsbundle

    react-native bundle --entry-file index.js --bundle-output ./ios/bundle/main.jsbundle --platform ios ...

  5. webstorm 2018 Eslint修复 快捷键设置

    首先确保eslint插件已安装 已勾选

  6. Word操作——通配符

    参考资料:https://www.cnblogs.com/whchensir/p/5768030.html (1)查找引号中的内容 (“*”) ^p\1^p (2)按照句号,分号换行,当有引号时不换行 ...

  7. rpm 包的安装:

    参考博客: https://www.cnblogs.com/lzj87980239/p/3611776.html 如果已经安装了一个 rpm 包, 然后这个安装包又重新打了, 但是安装包的名字没有修改 ...

  8. spring IOC 分析及实现

    什么是IOC Inversion of Control,控制反转,也成依赖倒置. 反转: 依赖对象的创建被反转,使用IOC之前,对象由自己创建,反转后,由IOC容器获取 IOC容器的工作: 负责创建, ...

  9. vue+element-ui实现表格checkbox单选

    公司平台利用vue+elementui搭建前端页面,因为本人第一次使用vue也遇到了不少坑,因为我要实现的效果如下图所示 实现这种单选框,只能选择一个,但element-ui展示的是多选框,check ...

  10. java中进程与线程的区别

    进程是一个正在运行的应用程序.一个进程包含一个或多个线程.它可以是一段完整的代码或部分程序的动态执行.系统资源分配与调度的基本单位.而线程是CPU调度与运行的基本单位,它是一组指令的集合或是程序的特殊 ...