Class CacheItem

  • All Implemented Interfaces:
    java.lang.Cloneable
    Direct Known Subclasses:
    InternalCacheItem

    public class CacheItem
    extends java.lang.Object
    implements java.lang.Cloneable
    NCache uses a "key" and "value" structure for storing objects in the cache. When an object is added in cache it is stored as value and metadata against the specified key. This combination of value and metadata is defined as CacheItem in NCache. The value of the objects stored in the cache can range from being simple string types to complex objects. CacheItem class in NCache has properties that enable you to set metadata for the item to be added in the cache in an organized way. In scenarios where multiple attributes have to be set while adding an item in the cache, using CacheItem is preferred. Using CacheItem class object removes the problem of using multiple API overloads on adding/updating data in the cache. You can easily use the basic API overload and add/update data easily using CacheItem.
    • Constructor Detail

      • CacheItem

        public CacheItem()
        Initialize new instance of CacheItem.
      • CacheItem

        public CacheItem​(java.lang.Object value)
        Initialize new instance of CacheItem.
        Parameters:
        value - Actual object to be stored in cache.
    • Method Detail

      • getExpiration

        public final Expiration getExpiration()
        Gets the expiration mechanism for CacheItem. After the specified timespan, the item expires from cache. If expiration is not set then it is disabled.
        Returns:
        Expiration instance that contains information about CacheItem expiration mechanism.
      • setExpiration

        public final void setExpiration​(Expiration value)
        Sets the expiration mechanism for CacheItem. After the specified timespan, the item expires from cache. If expiration is not set then it is disabled.
        Parameters:
        value - Expiration object that specifies the expiration mechanism for CacheItem.
      • getCacheItemPriority

        public final CacheItemPriority getCacheItemPriority()
        Gets the relative priority of items stored in the cache.
        Returns:
        CacheItemPriority associated with the CacheItem.
      • setCacheItemPriority

        public final void setCacheItemPriority​(CacheItemPriority value)
        Sets the relative priority of items stored in the cache.
        Parameters:
        value - CacheItemPriority to be associated with the CacheItem.
      • getCacheItemVersion

        public final CacheItemVersion getCacheItemVersion()
        Gets the version of each CacheItem. An instance of this class is used in the optimistic concurrency model to ensure the data integrity.
        Returns:
        The version associated with the CacheItem.
      • setCacheItemVersion

        public final void setCacheItemVersion​(CacheItemVersion value)
        Sets the version associated with the CacheItem. 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.
        Parameters:
        value - The version to be associated with the CacheItem.
      • getCreationTime

        public final java.util.Date getCreationTime()
        Gets the time when the item was added in the cache for the first time.
        Returns:
        The date of creation of the CacheItem.
      • getLastModifiedTime

        public final java.util.Date getLastModifiedTime()
        Gets the last modified time of the CacheItem. CacheItem stores the last modified time of the CacheItem. 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.
        Returns:
        The last modification time of the CacheItem.
      • getTags

        public final java.util.List<Tag> getTags()
        Gets the tags information associated with the CacheItem. Using Tags, you can associate keywords(s) with your cache items. You can mark your data with tags, which act as identifiers for your cache items.
        Returns:
        List of Tags associated with CacheItem.
      • setTags

        public final void setTags​(java.util.List<Tag> value)
        Sets the tags information associated with the CacheItem. Using Tags, you can associate keywords(s) with your cache items. You can mark your data with tags, which act as identifiers for your cache items.
        Parameters:
        value - List of Tags to be associated with CacheItem.
      • getNamedTags

        public final NamedTagsDictionary getNamedTags()
        Gets the NamedTags information associated with the CacheItem. With Named Tags, the user is able to store additional information (of any type) required to query the object stored as string.
        Returns:
        NamedTags associated with the CacheItem.
      • setNamedTags

        public final void setNamedTags​(NamedTagsDictionary value)
        Sets the NamedTags information associated with the CacheItem. With Named Tags, the user is able to store additional information (of any type) required to query the object stored as string.
        Parameters:
        value - NamedTags to be associated with CacheItem.
      • getResyncOptions

        public final ResyncOptions getResyncOptions()
        Gets the ResyncOptions specific to the CacheItem.
        Returns:
        ResyncOptions specific to the CacheItem.
      • setResyncOptions

        public final void setResyncOptions​(ResyncOptions value)
        Sets the ResyncOptions specific to the CacheItem.
        Parameters:
        value - ResyncOptions specific to the CacheItem.
      • getGroup

        public final java.lang.String getGroup()
        Gets the group associated with the CacheItem. Groups help you create a logical partition of your cached data for easy retrieval.
        Returns:
        The group associated with CacheItem.
      • setGroup

        public final void setGroup​(java.lang.String value)
        Sets the group associated with the CacheItem. Groups help you create a logical partition of your cached data for easy retrieval.
        Parameters:
        value - The group to be associated with CacheItem.
      • getSyncDependency

        public final CacheSyncDependency getSyncDependency()
        Synchronizes two separate caches so that an item updated or removed from one cache can have the same effect on the synchronized cache. For cache sync dependency, an item must exist in cache before another item can be added with a dependency on it. This property lets you set the cache sync dependency with a CacheItem.
        Returns:
        CacheSyncDependency associated with CacheItem.
      • setSyncDependency

        public final void setSyncDependency​(CacheSyncDependency value)
        Synchronizes two separate caches so that an item updated or removed from one cache can have the same effect on the synchronized cache. For cache sync dependency, an item must exist in cache before another item can be added with a dependency on it. This property lets you set the cache sync dependency with a CacheItem.
        Parameters:
        value - CacheSyncDependency to be associated with CacheItem.
      • getDependency

        public final CacheDependency getDependency()
        Gets 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.
        Returns:
        The cache dependency instance associated with CacheItem.
      • setDependency

        public final void setDependency​(CacheDependency value)
        Sets 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.
        Parameters:
        value - The cache dependency instance to be associated with CacheItem.
      • addCacheDataNotificationListener

        public final void addCacheDataNotificationListener​(CacheDataModificationListener listener,
                                                           java.util.EnumSet<EventType> eventType,
                                                           EventDataFilter 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 are inserted to. Listeners are overridden for the same event type/types, if called again.
        Parameters:
        listener - Listener to be raised when an item is updated or removed.
        eventType - Event type/types the listener is registered against.
        datafilter - Tells whether to receive metadata, data with metadata or none when a notification is triggered.
      • removeCacheDataNotificationListener

        public void removeCacheDataNotificationListener​(CacheDataModificationListener listener,
                                                        java.util.EnumSet<EventType> eventEnumSet)
        Unregisters the user from cache data modification notifications.
        Parameters:
        listener - The listener that is registered for notifications.
        eventEnumSet - Event type/types the listener is unregistered against.
      • getValue

        public final <T> T getValue​(java.lang.Class<?> cls)
                             throws OperationFailedException
        Returns the value stored in the CacheItem.
        Type Parameters:
        T - Specifies the type of value obtained from the CacheItem.
        Parameters:
        cls - Specifies the class of value obtained from the CacheItem.
        Returns:
        Value of the CacheItem with the type defined.
        Throws:
        OperationFailedException
      • setValue

        public void setValue​(java.lang.Object value)
        Sets the value of the CacheItem.
        Parameters:
        value - Object to be stored in the CacheItem.
      • clone

        public final java.lang.Object clone()
        Creates a shallow copy of the CacheItem.
        Returns:
        A shallow copy of the CacheItem.