Skip to content

Set

Stores an object in the cache.

$Cache.Set(key: string, value: any):void

Stores an object in the cache with a specified expiration duration.

$Cache.Set(key: string, value: any, duration: string):void

Parameters

string key
    The key to associate with the value.

any value
    The value to be stored.

string duration
    The expiration duration in "day.hh:mm:ss" format. Optional.

Remarks

If a duration is not specified, the object uses the underlying cache's default lifetime; this cache is not a durable store.

A duration can be specified in "day.hh:mm:ss" format.

Specifying null as the value removes the object from the cache.

Storing an object in the cache

1
2
3
4
var id = 1;
$Cache.Set("myObject:" + id, {
 Name : 'Madonna'
});
If a duration is not specified, the object uses the underlying cache's default lifetime; this cache is not a durable store.

Specifying null as the value removes the object from the cache.

Storing an object in the cache with a duration

1
2
3
4
var id = 1;
$Cache.Set("myObject:" + id, {
  Name : 'Madonna'
}, "12:00:00");

See Also