Language

Cache.Put Method (String, String, Object, Tag , CacheItemVersion, TimeSpan)

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

Adds a new object to the cache or replaces one if it is already located in the cache. This overload allows you to save your object to a region, update tags associated with the object, and specify an object time-out that overrides the default settings for the cache. This method also supports optimistic concurrency by accepting version information as a parameter.

Namespace: System.Data.Caching
Assembly: ClientLibrary (in clientlibrary.dll)

Syntax

'Declaration
Public Function Put ( _
    region As String, _
    key As String, _
    value As Object, _
    tags As Tag(), _
    oldVersion As CacheItemVersion, _
    timeOut As TimeSpan _
) As CacheItemVersion
'Usage
Dim instance As Cache
Dim region As String
Dim key As String
Dim value As Object
Dim tags As Tag()
Dim oldVersion As CacheItemVersion
Dim timeOut As TimeSpan
Dim returnValue As CacheItemVersion

returnValue = instance.Put(region, key, value, tags, oldVersion, timeOut)
public CacheItemVersion Put (
    string region,
    string key,
    Object value,
    Tag[] tags,
    CacheItemVersion oldVersion,
    TimeSpan timeOut
)
public:
CacheItemVersion^ Put (
    String^ region, 
    String^ key, 
    Object^ value, 
    array<Tag^>^ tags, 
    CacheItemVersion^ oldVersion, 
    TimeSpan timeOut
)
public CacheItemVersion Put (
    String region, 
    String key, 
    Object value, 
    Tag[] tags, 
    CacheItemVersion oldVersion, 
    TimeSpan timeOut
)
public function Put (
    region : String, 
    key : String, 
    value : Object, 
    tags : Tag[], 
    oldVersion : CacheItemVersion, 
    timeOut : TimeSpan
) : CacheItemVersion

Parameters

  • region
    The name of the region. Use DefaultRegion if the object is not stored in a region.
  • key
    The unique value that is used to identify the object in the cache. If this parameter is null, an exception is thrown.
  • value
    The object saved to the cache cluster.
  • tags
    An array of Tag objects to associate with the cached object inside the region. If the region name is not provided, all tags are ignored.
  • oldVersion
    The CacheItemVersion object that represents the version of the cached object that is updated. If null, the cached object is updated regardless.
  • timeOut
    A non-zero time to live (TTL) value that is used to specify how many minutes the object should reside in the cache before expiration.

Return Value

A CacheItemVersion object that represents the version of the cached object after it has been updated by this method. If the oldVersion parameter is non-null, and not equal to the version of the cached object before this method call, null is returned and the object is not updated.

Remarks

Tags may only be used to retrieve a cached object if that object is saved to a region. Until a region name is provided, tags are ignored.

By passing the oldVersion parameter, this method can maintain concurrency. If another process updates the cached object before this method is called, this method does not update the cached object and returns null. For more information about concurrency, see Concurrency Models (Velocity) and Concurrency Methods (Velocity).

If the oldVersion parameter is passed a null, the cached object is updated regardless of the version. This is useful when all that you want to do is update the tags associated with the object. For more information, see Tag-Based Methods (Velocity).

The timeOut value associated with the cached object overrides expiration settings specified in the named cache configuration. For more information, see Expiration and Eviction (Velocity).

See Also

Reference

Cache Class
Cache Members
System.Data.Caching Namespace