WebCache.Set Method
Inserts an item into the WebCache object.
Namespace: System.Web.Helpers
Assembly: System.Web.Helpers (in System.Web.Helpers.dll)
Syntax
'Declaration
Public Shared Sub Set ( _
key As String, _
value As Object, _
minutesToCache As Integer, _
slidingExpiration As Boolean _
)
'Usage
Dim key As String
Dim value As Object
Dim minutesToCache As Integer
Dim slidingExpiration As Boolean
WebCache.Set(key, value, minutesToCache, _
slidingExpiration)
public static void Set(
string key,
Object value,
int minutesToCache,
bool slidingExpiration
)
public:
static void Set(
String^ key,
Object^ value,
int minutesToCache,
bool slidingExpiration
)
static member Set :
key:string *
value:Object *
minutesToCache:int *
slidingExpiration:bool -> unit
public static function Set(
key : String,
value : Object,
minutesToCache : int,
slidingExpiration : boolean
)
Parameters
- key
Type: System.String
The identifier for the cache item.
- value
Type: System.Object
The data to insert into the cache.
- minutesToCache
Type: System.Int32
Optional. The number of minutes to keep an item in the cache. The default is 20.
- slidingExpiration
Type: System.Boolean
Optional. true to indicate that the cache item expiration is reset each time the item is accessed, or false to indicate that the expiration is based the absolute time since the item was added to the cache. The default is true. In that case, if you also use the default value for the minutesToCache parameter, a cached item expires 20 minutes after it was last accessed.
Exceptions
Exception | Condition |
---|---|
ArgumentOutOfRangeException | The value of minutesToCache is less than or equal to zero. |
ArgumentOutOfRangeException | Sliding expiration is enabled and the value of minutesToCache is greater than a year. |
Remarks
To cache data, call the Set method. For key, pass a key that identifies the item in the cache. For value, pass the data to cache. The data that you add to the cache can be any type of object, including complex data objects returned from database queries, arrays of values, or simple objects such as a number or a string.