Class CacheItem

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class CacheItem
    extends java.lang.Object
    implements java.lang.Cloneable
    NCache uses a "key" and "value" structure for storing objects in 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 cache in an organized way. In scenarios where multiple attributes have to be set while adding an item in cache using CacheItem is preferred.Using CacheItem class object removes the problem of using multiple API overloads on adding/updating data in cache.You can easily use the basic API overload and add/update data easily using CacheItem.
    • Constructor Summary

      Constructors 
      Constructor Description
      CacheItem()
      Initialize new instance of cache item.
      CacheItem​(java.lang.Object value)
      Initialize new instance of cache item.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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.
      java.lang.Object clone()
      Creates a shallow copy of CacheItem
      CacheItemPriority getCacheItemPriority()
      Gets the relative priority for cache item which is kept under consideration whenever cache starts to free up space and evicts items.
      CacheItemVersion getCacheItemVersion()
      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.
      java.util.Date getCreationTime()
      Gets the time when the item was added in cache for the first time.
      CacheDependency getDependency()
      Gets the Cache Dependency instance that contains all dependencies associated with cache item.
      Expiration getExpiration()
      Gets the expiration mechanism for cache item.
      java.lang.String getGroup()
      Gets the group associated with the cache item.
      java.util.Date getLastModifiedTime()
      Gets the lastModifiedTime of the cache item.CacheItem stores the last modified time of the cache item.
      NamedTagsDictionary getNamedTags()
      Gets the NamedTags information associated with the cache item, it can be queried on the basis of NamedTags provided.
      ResyncOptions getResyncOptions()
      Gets the ResyncOptions specific to the cache item.
      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.
      java.util.List<Tag> getTags()
      Gets the tags information associated with the cache item, it can be queried on the basis of Tags provided.
      <T> T getValue​(java.lang.Class<?> cls)
      Returns the value stored in the cache item.
      void removeCacheDataNotificationListener​(CacheDataModificationListener listener, java.util.EnumSet<EventType> eventEnumSet)
      Unregisters the user from cache data modification notifications.
      void setCacheItemPriority​(CacheItemPriority value)
      Sets the relative priority for cache item which is kept under consideration whenever cache starts to free up space and evicts items.
      void setCacheItemVersion​(CacheItemVersion value)
      Sets 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.
      void setDependency​(CacheDependency value)
      Sets the Cache Dependency instance that contains all dependencies associated with cache item.
      void setExpiration​(Expiration value)
      Sets the expiration mechanism for cache item.
      void setGroup​(java.lang.String value)
      Sets the group associated with the cache item.
      void setNamedTags​(NamedTagsDictionary value)
      Sets the NamedTags information associated with the cache item, it can be queried on the basis of NamedTags provided.
      void setResyncOptions​(ResyncOptions value)
      Sets the ResyncOptions specific to the cache item.
      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.
      void setTags​(java.util.List<Tag> value)
      Sets the tags information associated with the cache item, it can be queried on the basis of Tags provided.
      void setValue​(java.lang.Object value)
      Sets the value of the cache item.
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CacheItem

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

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

      • getExpiration

        public final Expiration getExpiration()
        Gets the expiration mechanism for cache item.
        Returns:
        Expiration instance that contains info about cache item expiration mechanism.
      • setExpiration

        public final void setExpiration​(Expiration value)
        Sets the expiration mechanism for cache item.
        Parameters:
        value - Expiration object that specifies the expiration mechanism for cache item.
      • getCacheItemPriority

        public final CacheItemPriority getCacheItemPriority()
        Gets the relative priority for cache item which is kept under consideration whenever cache starts to free up space and evicts items.
        Returns:
        CacheItemPriority associated with cache item.
      • setCacheItemPriority

        public final void setCacheItemPriority​(CacheItemPriority value)
        Sets the relative priority for cache item which is kept under consideration whenever cache starts to free up space and evicts items.
        Parameters:
        value - CacheItemPriority to be associated with cache item.
      • getCacheItemVersion

        public final CacheItemVersion getCacheItemVersion()
        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.
        Returns:
        The version associated with the cache item.
      • setCacheItemVersion

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

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

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

        public final java.util.List<Tag> getTags()
        Gets the tags information associated with the cache item, it can be queried on the basis of Tags provided.
        Returns:
        List of Tags associated with cache item.
      • setTags

        public final void setTags​(java.util.List<Tag> value)
        Sets the tags information associated with the cache item, it can be queried on the basis of Tags provided.
        Parameters:
        value - List of Tags to be associated with cache item.
      • getNamedTags

        public final NamedTagsDictionary getNamedTags()
        Gets the NamedTags information associated with the cache item, it can be queried on the basis of NamedTags provided.
        Returns:
        NamedTags associated with cache item.
      • setNamedTags

        public final void setNamedTags​(NamedTagsDictionary value)
        Sets the NamedTags information associated with the cache item, it can be queried on the basis of NamedTags provided.
        Parameters:
        value - NamedTags to be associated with cache item.
      • getResyncOptions

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

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

        public final java.lang.String getGroup()
        Gets the group associated with the cache item. It can be queryed on the basis of Groups.
        Returns:
        The group associated with cache item.
      • setGroup

        public final void setGroup​(java.lang.String value)
        Sets the group associated with the cache item. It can be queryed on the basis of Groups.
        Parameters:
        value - The group to be associated with cache item.
      • 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 Cache sync dependency with a cache item.
        Returns:
        CacheSyncDependency associated with cache item.
      • 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 Cache sync dependency with a cache item.
        Parameters:
        value - CacheSyncDependency to be associated with cache item.
      • getDependency

        public final CacheDependency getDependency()
        Gets the Cache Dependency instance that contains all dependencies associated with cache item.
        Returns:
        The Cache Dependency instance associated with cache item.
      • setDependency

        public final void setDependency​(CacheDependency value)
        Sets the Cache Dependency instance that contains all dependencies associated with cache item.
        Parameters:
        value - The Cache Dependency instance to be associated with cache item.
      • 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 is 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 cache item. This value must be serializable.
        Type Parameters:
        T - Specifies the type of value obtained from the cache item.
        Parameters:
        cls - Specifies the class of value obtained from the cache item.
        Returns:
        Value of the cache item with the class defined.
        Throws:
        OperationFailedException
      • setValue

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

        public final java.lang.Object clone()
        Creates a shallow copy of CacheItem
        Overrides:
        clone in class java.lang.Object
        Returns:
        The cloned object.