Class CacheItem<T>
The item which will be stored in the cache holding the cache value and additional information needed by the cache handles and manager.
Inherited Members
Namespace:CacheManager.Core
Assembly:CacheManager.Core.dll
Syntax
[Serializable]
public class CacheItem<T> : ISerializable, ICacheItemProperties
Type Parameters
Name | Description |
---|---|
T | The type of the cache value. |
Constructors
| Improve this Doc View SourceCacheItem()
Initializes a new instance of the CacheItem<T> class.
Declaration
protected CacheItem()
CacheItem(SerializationInfo, StreamingContext)
Initializes a new instance of the CacheItem<T> class.
Declaration
protected CacheItem(SerializationInfo info, StreamingContext context)
Parameters
Type | Name | Description |
---|---|---|
SerializationInfo | info | The information. |
StreamingContext | context | The context. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If info is null. |
CacheItem(String, T)
Initializes a new instance of the CacheItem<T> class.
Declaration
public CacheItem(string key, T value)
Parameters
Type | Name | Description |
---|---|---|
String | key | The cache key. |
T | value | The cache value. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If key or value are null. |
CacheItem(String, T, ExpirationMode, TimeSpan)
Initializes a new instance of the CacheItem<T> class.
Declaration
public CacheItem(string key, T value, ExpirationMode expiration, TimeSpan timeout)
Parameters
Type | Name | Description |
---|---|---|
String | key | The cache key. |
T | value | The cache value. |
ExpirationMode | expiration | The expiration mode. |
TimeSpan | timeout | The expiration timeout. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If key or value are null. |
CacheItem(String, String, T)
Initializes a new instance of the CacheItem<T> class.
Declaration
public CacheItem(string key, string region, T value)
Parameters
Type | Name | Description |
---|---|---|
String | key | The cache key. |
String | region | The cache region. |
T | value | The cache value. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If key, value or region are null. |
CacheItem(String, String, T, ExpirationMode, TimeSpan)
Initializes a new instance of the CacheItem<T> class.
Declaration
public CacheItem(string key, string region, T value, ExpirationMode expiration, TimeSpan timeout)
Parameters
Type | Name | Description |
---|---|---|
String | key | The cache key. |
String | region | The cache region. |
T | value | The cache value. |
ExpirationMode | expiration | The expiration mode. |
TimeSpan | timeout | The expiration timeout. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If key, value or region are null. |
Properties
| Improve this Doc View SourceCreatedUtc
Gets the creation date of the cache item.
Declaration
public DateTime CreatedUtc { get; }
Property Value
Type | Description |
---|---|
DateTime | The creation date. |
Implements
| Improve this Doc View SourceExpirationMode
Gets the expiration mode.
Declaration
public ExpirationMode ExpirationMode { get; }
Property Value
Type | Description |
---|---|
ExpirationMode | The expiration mode. |
Implements
| Improve this Doc View SourceExpirationTimeout
Gets the expiration timeout.
Declaration
public TimeSpan ExpirationTimeout { get; }
Property Value
Type | Description |
---|---|
TimeSpan | The expiration timeout. |
Implements
| Improve this Doc View SourceIsExpired
Gets a value indicating whether the item is logically expired or not. Depending on the cache vendor, the item might still live in the cache although according to the expiration mode and timeout, the item is already expired.
Declaration
public bool IsExpired { get; }
Property Value
Type | Description |
---|---|
Boolean |
Key
Gets the cache key.
Declaration
public string Key { get; }
Property Value
Type | Description |
---|---|
String | The cache key. |
Implements
| Improve this Doc View SourceLastAccessedUtc
Gets or sets the last accessed date of the cache item.
Declaration
public DateTime LastAccessedUtc { get; set; }
Property Value
Type | Description |
---|---|
DateTime | The last accessed date. |
Implements
| Improve this Doc View SourceRegion
Gets the cache region.
Declaration
public string Region { get; }
Property Value
Type | Description |
---|---|
String | The cache region. |
Implements
| Improve this Doc View SourceUsesExpirationDefaults
Gets a value indicating whether the cache item uses the cache handle's configured expiration.
Declaration
public bool UsesExpirationDefaults { get; }
Property Value
Type | Description |
---|---|
Boolean |
Implements
| Improve this Doc View SourceValue
Gets the cache value.
Declaration
public T Value { get; }
Property Value
Type | Description |
---|---|
T | The cache value. |
ValueType
Gets the type of the cache value.
This might be used for serialization and deserialization.
Declaration
public Type ValueType { get; }
Property Value
Type | Description |
---|---|
Type | The type of the cache value. |
Implements
Methods
| Improve this Doc View SourceGetObjectData(SerializationInfo, StreamingContext)
Populates a SerializationInfo with the data needed to serialize the target object.
Declaration
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
Type | Name | Description |
---|---|---|
SerializationInfo | info | The SerializationInfo to populate with data. |
StreamingContext | context | The destination (see StreamingContext) for this serialization. |
Implements
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If info is null. |
ToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String |
Overrides
| Improve this Doc View SourceWithAbsoluteExpiration(DateTimeOffset)
Creates a copy of the current cache item and sets a new absolute expiration date.
This method doesn't change the state of the item in the cache. Use Put
or similar methods to update the cache with the returned copy of the item.
Declaration
public CacheItem<T> WithAbsoluteExpiration(DateTimeOffset absoluteExpiration)
Parameters
Type | Name | Description |
---|---|---|
DateTimeOffset | absoluteExpiration | The absolute expiration date. |
Returns
Type | Description |
---|---|
CacheItem<T> | The new instance of the cache item. |
Remarks
We do not clone the cache item or value.
WithAbsoluteExpiration(TimeSpan)
Creates a copy of the current cache item and sets a new absolute expiration date.
This method doesn't change the state of the item in the cache. Use Put
or similar methods to update the cache with the returned copy of the item.
Declaration
public CacheItem<T> WithAbsoluteExpiration(TimeSpan absoluteExpiration)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | absoluteExpiration | The absolute expiration date. |
Returns
Type | Description |
---|---|
CacheItem<T> | The new instance of the cache item. |
Remarks
We do not clone the cache item or value.
WithCreated(DateTime)
Creates a copy of the current cache item with a given created date.
This method doesn't change the state of the item in the cache. Use Put
or similar methods to update the cache with the returned copy of the item.
Declaration
public CacheItem<T> WithCreated(DateTime created)
Parameters
Type | Name | Description |
---|---|---|
DateTime | created | The new created date. |
Returns
Type | Description |
---|---|
CacheItem<T> | The new instance of the cache item. |
Remarks
We do not clone the cache item or value.
WithDefaultExpiration()
Creates a copy of the current cache item with no explicit expiration, instructing the cache to use the default defined in the cache handle configuration.
This method doesn't change the state of the item in the cache. Use Put
or similar methods to update the cache with the returned copy of the item.
Declaration
public CacheItem<T> WithDefaultExpiration()
Returns
Type | Description |
---|---|
CacheItem<T> | The new instance of the cache item. |
Remarks
We do not clone the cache item or value.
WithNoExpiration()
Creates a copy of the current cache item without expiration. Can be used to update the cache
and remove any previously configured expiration of the item.
This method doesn't change the state of the item in the cache. Use Put
or similar methods to update the cache with the returned copy of the item.
Declaration
public CacheItem<T> WithNoExpiration()
Returns
Type | Description |
---|---|
CacheItem<T> | The new instance of the cache item. |
Remarks
We do not clone the cache item or value.
WithSlidingExpiration(TimeSpan)
Creates a copy of the current cache item and sets a new sliding expiration value.
This method doesn't change the state of the item in the cache. Use Put
or similar methods to update the cache with the returned copy of the item.
Declaration
public CacheItem<T> WithSlidingExpiration(TimeSpan slidingExpiration)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | slidingExpiration | The sliding expiration value. |
Returns
Type | Description |
---|---|
CacheItem<T> | The new instance of the cache item. |
Remarks
We do not clone the cache item or value.
WithValue(T)
Creates a copy of the current cache item with new value.
This method doesn't change the state of the item in the cache. Use Put
or similar methods to update the cache with the returned copy of the item.
Declaration
public CacheItem<T> WithValue(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The new value. |
Returns
Type | Description |
---|---|
CacheItem<T> | The new instance of the cache item. |
Remarks
We do not clone the cache item or value.