Constructor
# new CacheItem(value, type)
Initialize new instance of cache item.
Name | Type | Default | Description |
---|---|---|---|
value |
Any | null | Actual object to be stored in cache. |
type |
JsonDataType | null |
const ncache = require('ncache-client');
//Initialize the Cache Cluster
let cache = await ncache.CacheManager.getCache("test-Cache");
//Create new CacheItem
let cacheItem = new ncache.CacheItem("Value");
//set cache item expiration
let timeSpan = new ncache.TimeSpan(0, 0, 0, 1, 0, 0);
let expiration = new ncache.Expiration(ExpirationType.Absolute, timeSpan);
cacheItem.setExpiration(expiration);
//set cacahe item Priority
cacheItem.setCacheItemPriority(CacheItemPriority.High);
//Add cache item in Cache
await cache.add('key', cacheItem);
//close the cache
await cache.close();
Methods
# addCacheDataNotificationListener(listener, eventType, datafilter)
You can use this to notify applications when their objects are updated or removed in the cache. Listeners can be registered against event type/types for the key the items is inserted to. Listeners are overridden for the same event type/types if called again.
Name | Type | Description |
---|---|---|
listener |
CacheDataModificationListener | Callback to be raised when an item is updated or removed. |
eventType |
Array | EventType the callback is registered against |
datafilter |
number | Tells whether to receive metadata, data with metadata or none when a notification is triggered. |
# getCacheItemPriority() → {CacheItemPriority}
Gets the relative priority for cache item which is kept under consideration whenever cache starts to free up space and evicts items.
CacheItemPriority associated with cache item.
- Type
- CacheItemPriority
# getCacheItemVersion() → {CacheItemVersion}
Gets the version associated with the cache item.Version is basically a numeric value that is used to represent the version of the cached item which changes with every update to an item.
The version associated with the cache item.
- Type
- CacheItemVersion
# getCreationTime() → {Date}
Gets the time when the item was added in cache for the first time.
The date of creation of the cache item.
- Type
- Date
# getDependency() → {CacheDependency}
Gets the Cache Dependency instance that contains all dependencies associated with cache item.
The Cache Dependency instance associated with cache item.
- Type
- CacheDependency
# getExpiration() → {Expiration}
Gets the expiration mechanism for cache item.
instance that contains info about cache item expiration mechanism.
- Type
- Expiration
# getGroup() → {string}
Gets the group associated with the cache item. It can be queryed on the basis of Groups.
The group associated with cache item.
- Type
- string
# getLastModifiedTime() → {Date}
Gets the lastModifiedTime of the cache item.CacheItem stores the last modified time of the cache item. If an item is updated in cache its last modified time is updated as well. Last modified time is checked when Least Recently Used based eviction is triggered.
The last modification time of the cache item.
- Type
- Date
# getNamedTags() → {NamedTagsDictionary}
Gets the NamedTags information associated with the cache item, it can be queried on the basis of NamedTags provided.
NamedTags associated with cache item.
- Type
- NamedTagsDictionary
# getResyncOptions() → {ResyncOptions}
Gets the ResyncOptions specific to the cache item.
ResyncOptions specific to the cache item.
- Type
- ResyncOptions
# getTags() → {Array.<Tag>}
Gets the tags information associated with the cache item, it can be queried on the basis of Tags provided.
List of Tags associated with cache item.
- Type
- Array.<Tag>
# getValue(classOb)
Returns the value stored in the cache item.
Name | Type | Description |
---|---|---|
classOb |
JsonDataType | Specifies the type of value obtained from the cacheItem. |
Object
# removeCacheDataNotificationListener(listener, eventEnumSet)
Unregisters the user from cache data modification notifications.
Name | Type | Description |
---|---|---|
listener |
CacheDataModificationListener | The listener that is registered for notifications. |
eventEnumSet |
Array | Event type/types the listener is unregistered against. |
# setCacheItemPriority(value)
Sets the CacheItemPriority of the cache item.
Name | Type | Description |
---|---|---|
value |
number | Sets the CacheItemPriority of the cache item. |
# setCacheItemVersion(value)
Sets the CacheItemVersion of the cache item.
Name | Type | Description |
---|---|---|
value |
CacheItemVersion | It is basically a numeric value that is used to represent the version of the cached item which changes with every update to an item. |
# setDependency(value)
sets CacheDependency of CacheItem
Name | Type | Description |
---|---|---|
value |
CacheDependency | sets CacheDependency of CacheItem |
# setExpiration(value)
Sets the Expiration of the cache item.
Name | Type | Description |
---|---|---|
value |
Expiration | This property sets Expiration for the cache itme. After the specified timespan, the item expires from cache. |
# setGroup(value)
Sets the group associated with the cache item. It can be queryed on the basis of Groups.
Name | Type | Description |
---|---|---|
value |
string | The group to be associated with cache item. |
# setNamedTags(value)
sets NamedTags of CacheItem
Name | Type | Description |
---|---|---|
value |
NamedTagsDictionary | NCache then allows you to search your objects through these named tags. Named tags can be specified by using this property of CacheItem. |
# setResyncOptions(value)
sets ResyncOption of CacheItem
Name | Type | Description |
---|---|---|
value |
ResyncOptions | sets ResyncOptions of a cache item |
# setTags(value)
Sets the tags information associated with the cache item, it can be queried on the basis of Tags provided.
Name | Type | Description |
---|---|---|
value |
Array.<Tag> | List of Tags to be associated with cache item. |
# setValue(value, type)
Sets the value of the cache item.
Name | Type | Default | Description |
---|---|---|---|
value |
Any | Actual object to be stored in cache. |
|
type |
string | null |