Class CacheItem
Class that represents a cached item including its dependencies, expiration and eviction information
Inheritance
Namespace:
Assembly: Alachisoft.NCache.Web.dll
Syntax
public class CacheItem : ICloneable
Examples
You can create an instance of CacheItem class and Add(String, Object) it to the Cache
object someData = new object();
CacheItem item = new CacheItem(someData);
item.SlidingExpiration = new TimeSpan(0,5,0);
item.Priority = CacheItemPriority.High;
item.ItemRemoveCallback = onRemove;
Cache cache = NCache.InitializeCache("myCache");
cache.Add("someData", item);
CacheItem(Object)
Costructor
Declaration
public CacheItem(object value)
Parameters
Type | Name | Description |
---|---|---|
System.Object | value | Actual object to be stored in cache |
AbsoluteExpiration
The time at which the added object expires and is removed from the cache.
Declaration
public DateTime AbsoluteExpiration { get; set; }
Property Value
Type | Description |
---|---|
System.DateTime | The default value is Cache.NoAbsoluteExpiration |
Remarks
You cannot set both sliding and absolute expirations on the same cached item. If you do so, an System.ArgumentException is thrown when you will try to add or insert the CacheItem.
AsyncItemAddCallback
A delegate that, if provided, is called when an Asynchronous request for Add Operation completes. You can use this to obtain the results of an 'AddAsync' operation.
Declaration
public AsyncItemAddedCallback AsyncItemAddCallback { get; set; }
Property Value
Type | Description |
---|---|
AsyncItemAddedCallback |
AsyncItemUpdateCallback
A delegate that, if provided, is called when an Asynchronous request for Update Operation completes. You can use this to obtain the results of an 'InsertAsync' operation.
Declaration
public AsyncItemUpdatedCallback AsyncItemUpdateCallback { get; set; }
Property Value
Type | Description |
---|---|
AsyncItemUpdatedCallback |
CreationTime
Get the cache item creation time
Declaration
public DateTime CreationTime { get; }
Property Value
Type | Description |
---|---|
System.DateTime |
Dependency
The file or cache key dependencies for the item. When any dependency changes, the object becomes invalid and is removed from the cache. If there are no dependencies, this property contains a null reference (Nothing in Visual Basic).
Declaration
public CacheDependency Dependency { get; set; }
Property Value
Type | Description |
---|---|
CacheDependency |
Group
The name of the group to associate with the cache item. All cache items with the same group name are logically grouped together.
Declaration
public string Group { get; set; }
Property Value
Type | Description |
---|---|
System.String |
IsResyncExpiredItems
Gets/Sets a value indicating whether the object when expired will cause a refetch of the object from the master datasource. (Resync Expired Items)
Declaration
public bool IsResyncExpiredItems { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | true if "Resync Expired Items" on this object has been set; otherwise, false. The default is false. |
Remarks
Whenever an expired item is fectched from the cache it is read thru the datasource. If the item is not available in the datasource the item is removed from the cache and null value is returned.
Note: For "Resync Expired Items" to work you must a specify read through provider for the cache. For more information on read through providers see online documentation.
ItemRemoveCallback
A delegate that, if provided, is called when an object is removed from the cache. You can use this to notify applications when their objects are deleted from the cache.
Declaration
[Obsolete("This delegate is deprecated. 'Please use SetCacheDataNotification(CacheDataNotificationCallback callback, EventType eventType, EventDataFilter datafilter)'", false)]
public CacheItemRemovedCallback ItemRemoveCallback { get; set; }
Property Value
Type | Description |
---|---|
CacheItemRemovedCallback |
ItemUpdateCallback
A delegate that, if provided, is called when an object is updated in the cache. You can use this to notify applications when their objects are updated in the cache.
Declaration
[Obsolete("This delegate is deprecated. 'Please use SetCacheDataNotification(CacheDataNotificationCallback callback, EventType eventType, EventDataFilter datafilter)'", false)]
public CacheItemUpdatedCallback ItemUpdateCallback { get; set; }
Property Value
Type | Description |
---|---|
CacheItemUpdatedCallback |
LastModifiedTime
Get the cache item last modified time
Declaration
public DateTime LastModifiedTime { get; }
Property Value
Type | Description |
---|---|
System.DateTime |
NamedTags
Get or set the named tags
Declaration
public NamedTagsDictionary NamedTags { get; set; }
Property Value
Type | Description |
---|---|
NamedTagsDictionary |
Priority
The relative cost of the object, as expressed by the enumeration. The cache uses this value when it evicts objects; objects with a lower cost are removed from the cache before objects with a higher cost.
Declaration
public CacheItemPriority Priority { get; set; }
Property Value
Type | Description |
---|---|
CacheItemPriority | The default value is CacheItemPriority.Default. |
Remarks
This property will be used only when the eviction policy is set to priority in the configuration.
ResyncProviderName
Gets/Sets Provider name for re-synchronization of cache
Declaration
public string ResyncProviderName { get; set; }
Property Value
Type | Description |
---|---|
System.String |
SlidingExpiration
The interval between the time the added object was last accessed and when that object expires. If this value is the equivalent of 20 minutes, the object expires and is removed from the cache 20 minutes after it is last accessed.
Declaration
public TimeSpan SlidingExpiration { get; set; }
Property Value
Type | Description |
---|---|
System.TimeSpan | The default value is Cache.NoSlidingExpiration. |
Remarks
If the slidingExpiration property is set to NoSlidingExpiration,
sliding expiration is disabled. If you set the slidingExpiration
parameter to less than System.TimeSpan.Zero, or the equivalent of
more than one year, an System.ArgumentOutOfRangeException is thrown when you will try to
add or insert the CacheItem.
You cannot set both sliding and absolute expirations on the
same cached item. If you do so, an System.ArgumentException is thrown when you will try to
add or insert the CacheItem.
SubGroup
The name of the sub-group within a group. This hierarchical grouping gives more control over the cache items.
Declaration
public string SubGroup { get; set; }
Property Value
Type | Description |
---|---|
System.String |
SyncDependency
CacheSyncDependency for this item.
Declaration
public CacheSyncDependency SyncDependency { get; set; }
Property Value
Type | Description |
---|---|
CacheSyncDependency |
Tags
Get or set the tags
Declaration
public Tag[] Tags { get; set; }
Property Value
Type | Description |
---|---|
Tag[] |
Value
The actual object provided by the client application.
Declaration
public virtual object Value { get; set; }
Property Value
Type | Description |
---|---|
System.Object |
Remarks
This value must be serializable, otherwise System.ArgumentException is thrown when you will try to add or insert the CacheItem.
Version
Get or Set the cache item version
Declaration
public CacheItemVersion Version { get; set; }
Property Value
Type | Description |
---|---|
CacheItemVersion |
Clone()
Creates a shallow copy of CacheItem
Declaration
public object Clone()
Returns
Type | Description |
---|---|
System.Object |
SetCacheDataNotification(CacheDataNotificationCallback, EventType)
You can use this to notify applications when their objects are updated or removed in the cache. Callbacks can be registered against Alachisoft.NCache.Runtime.Events.EventType for the key the items is inserted to. Callback are overriden for the same Alachisoft.NCache.Runtime.Events.EventType if called again. Alachisoft.NCache.Runtime.Events.EventType.ItemAdded is not supported yet.
Declaration
public void SetCacheDataNotification(CacheDataNotificationCallback callback, EventType eventType)
Parameters
Type | Name | Description |
---|---|---|
CacheDataNotificationCallback | callback | Callback to be raised when an item is updated or removed |
Alachisoft.NCache.Runtime.Events.EventType | eventType | Alachisoft.NCache.Runtime.Events.EventType the callback is registered against |
SetCacheDataNotification(CacheDataNotificationCallback, EventType, EventDataFilter)
You can use this to notify applications when their objects are updated or removed in the cache. Callbacks can be registered against Alachisoft.NCache.Runtime.Events.EventType for the key the items is inserted to. To register different Alachisoft.NCache.Runtime.Events.EventDataFilter for different Alachisoft.NCache.Runtime.Events.EventType, you can call this function mutiple times with a different Alachisoft.NCache.Runtime.Events.EventType. Callback are overriden for the same Alachisoft.NCache.Runtime.Events.EventType if called again. Alachisoft.NCache.Runtime.Events.EventType.ItemAdded is not supported yet.
Declaration
public void SetCacheDataNotification(CacheDataNotificationCallback callback, EventType eventType, EventDataFilter datafilter)
Parameters
Type | Name | Description |
---|---|---|
CacheDataNotificationCallback | callback | Callback to be raised when an item is updated or removed |
Alachisoft.NCache.Runtime.Events.EventType | eventType | Alachisoft.NCache.Runtime.Events.EventType the callback is registered against |
Alachisoft.NCache.Runtime.Events.EventDataFilter | datafilter | Alachisoft.NCache.Runtime.Events.EventDataFilter for every Alachisoft.NCache.Runtime.Events.EventType registered against |