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;
}
}