From Cache Class:
The instance of Cache
that is accessed by the snippet below is a member of the Page
object that this sample inherits.
Your code must be in a Page
method. You have also another instance available on the HttpContext
, again, described on the same link:
One instance of this class is created per application domain, and it remains valid as long as the application domain remains active. Information about an instance of this class is available through the Cache
property of the HttpContext
object or the Cache
property of the Page
object.
You have to consider that Cache["<somestring>"]
it must be an instance, not the class, since a class cannot have a static index accessor. So any sample you see like that, it must be a an instance, likely a property named Cache
of some object.