Modul ncache.client.CacheItem

Erweitern Sie den Quellcode
import inspect
from datetime import datetime
from typing import Callable

from ncache.runtime.caching.events.CacheDataModificationListener import CacheDataModificationListener
from ncache.runtime.dependencies.FileDependency import FileDependency
from ncache.runtime.dependencies.KeyDependency import KeyDependency
from ncache.runtime.dependencies.OracleCacheDependency import OracleCacheDependency
from ncache.runtime.dependencies.SqlCacheDependency import SqlCacheDependency
from ncache.runtime.util.EnumUtil import EnumUtil
from ncache.util.EventsListenerHelper import EventsListenerHelper
from ncache.util.JavaInstancesFactory import *
from ncache.util.ValidateType import ValidateType
from ncache.client.enum.EventType import EventType
from ncache.client.enum.EventDataFilter import EventDataFilter
from ncache.client.enum.CacheItemPriority import CacheItemPriority
from ncache.runtime.dependencies.CacheDependency import CacheDependency
from ncache.runtime.Expiration import Expiration
from ncache.runtime.caching.NamedTagsDictionary import NamedTagsDictionary
from ncache.runtime.caching.datasource.ResyncOptions import ResyncOptions
from ncache.runtime.caching.Tag import Tag
from ncache.client.CacheItemVersion import CacheItemVersion
from ncache.util.TypeCaster import TypeCaster


class CacheItem:
    """
    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.
    """
    def __init__(self, value=None):
        """
        Initialize new instance of cache item.

        :param value: Actual object to be stored in cache.
        :type value: object
        """

        if value is None:
            self.__cacheitem = JavaInstancesFactory.get_java_instance("CacheItem")()
        else:
            javatype = TypeCaster.is_python_primitive(value)
            if javatype is not None:
                self.__cacheitem = JavaInstancesFactory.get_java_instance("CacheItem")(javatype)
            else:
                self.__cacheitem = JavaInstancesFactory.get_java_instance("CacheItem")(TypeCaster.serialize(value, isjsonobject=True, verbose=True))

    def set_instance(self, value):
        self.__cacheitem = value

    def get_instance(self):
        return self.__cacheitem

    def add_cache_data_notification_listener(self, callablefunction, eventtypes, 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 against.

        :param callablefunction: Callable function to be invoked when an item is updated or removed. This
        function should follow this signature: callablefunction(key: str, eventarg: CacheEventArg)
        :type callablefunction: Callable
        :param eventtypes: List of Event types the listener is registered against.
        :type eventtypes: list
        :param datafilter: Tells whether to receive metadata, data with metadata or none when a notification is
            triggered.
        :type datafilter: EventDataFilter
        """
        ValidateType.params_check(callablefunction, 2, self.add_cache_data_notification_listener)
        for item in eventtypes:
            ValidateType.type_check(item, EventType, self.add_cache_data_notification_listener)
        ValidateType.type_check(datafilter, EventDataFilter, self.add_cache_data_notification_listener)

        eventlistener = EventsListenerHelper.get_listener(callablefunction, CacheDataModificationListener)
        javaeventtypes = EventsListenerHelper.get_event_type_enum_set(eventtypes)
        javadatafilter = EnumUtil.get_event_data_filter(datafilter.value)

        self.__cacheitem.addCacheDataNotificationListener(eventlistener, javaeventtypes, javadatafilter)

    def get_cache_item_priority(self):
        """
        Gets the relative priority for cache item which is kept under consideration whenever cache starts to free up
        space and evicts items.

        :return: CacheItemPriority associated with cache item.
        :rtype: CacheItemPriority
        """
        result = self.__cacheitem.getCacheItemPriority()

        enumtype = None
        if result is not None:
            enumtype = EnumUtil.get_cache_item_priority_value(result)

        return enumtype

    def get_cache_item_version(self):
        """
        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.

        :return: The version associated with the cache item.
        :rtype: CacheItemVersion
        """
        version = self.__cacheitem.getCacheItemVersion()

        if version is not None:
            version = CacheItemVersion(int(version.getVersion()))

        return version

    def get_creation_time(self):
        """
        Gets the time when the item was added in cache for the first time.

        :return: The date of creation of the cache item.
        :rtype: datetime
        """
        result = self.__cacheitem.getCreationTime()

        if result is not None:
            result = TypeCaster.to_python_date(result)

        return result

    def get_dependency(self):
        """
        Gets the Cache Dependency instance that contains all dependencies associated with cache item.

        :return: The Cache Dependency instance associated with cache item.
        :rtype: CacheDependency
        """
        result = self.__cacheitem.getDependency()
        dependencytype = EnumUtil.get_dependency_type_info(result)
        dependency = None

        if dependencytype == 1:
            dependency = KeyDependency("key")
            dependency.set_instance(result)
        elif dependencytype == 2:
            dependency = FileDependency("key")
            dependency.set_instance(result)
        elif dependencytype == 5:
            dependency = SqlCacheDependency("ConString", "CmdText")
            dependency.set_instance(result)
        elif dependencytype == 6:
            dependency = OracleCacheDependency("ConString", "CmdText")
            dependency.set_instance(result)
        else:
            dependency = CacheDependency()
            dependency.set_instance(result)

        return dependency

    def get_expiration(self):
        """
        Gets the expiration mechanism for cache item.

        :return: Expiration instance that contains info about cache item expiration mechanism.
        :rtype: Expiration
        """
        result = self.__cacheitem.getExpiration()

        if result is not None:
            expiration = Expiration()
            expiration.set_instance(result)
            return expiration

        return result

    def get_group(self):
        """
        Gets the group associated with the cache item. It can be queried on the basis of Groups.

        :return: The group associated with cache item.
        :rtype: str
        """
        result = self.__cacheitem.getGroup()

        if result is not None:
            result = TypeCaster.to_python_primitive_type(result)

        return result

    def get_last_modified_time(self):
        """
        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.

        :return: The last modification time of the cache item.
        :rtype: datetime
        """
        result = self.__cacheitem.getLastModifiedTime()

        if result is not None:
            timestamp = float(result.getTime())
            result = datetime.fromtimestamp(timestamp / 1000)

        return result

    def get_named_tags(self):
        """
        Gets the NamedTags information associated with the cache item, it can be queried on the basis of NamedTags
        provided.

        :return: NamedTags associated with cache item.
        :rtype: NamedTagsDictionary
        """
        result = self.__cacheitem.getNamedTags()

        if result is not None:
            obj = NamedTagsDictionary()
            obj.set_instance(result)
            return obj

        return result

    def get_resync_options(self):
        """
        Gets the ResyncOptions specific to the cache item.

        :return: ResyncOptions specific to the cache item.
        :rtype: ResyncOptions
        """
        result = self.__cacheitem.getResyncOptions()

        if result is not None:
            resyncoptions = ResyncOptions(False)
            resyncoptions.set_instance(result)
            return resyncoptions

        return result

    def get_tags(self):
        """
        Gets the tags information associated with the cache item, it can be queried on the basis of Tags provided.

        :return: List of Tags associated with cache item.
        :rtype: list
        """
        result = self.__cacheitem.getTags()
        if result is not None:
            result = TypeCaster.to_python_list(result, False, Tag("DummyTag"))
        return result

    def get_value(self, objtype):
        """
        Returns the value stored in the cache item.

        :param objtype: Specifies the type of value obtained from the cacheItem.
        :type objtype: type
        :return: Returns the value stored in the cache item.
        :rtype: object
        """
        ValidateType.type_check(objtype, type, self.get_value)

        pythontype, javatype = TypeCaster.is_java_primitive(objtype)

        if javatype is not None:
            return pythontype(self.__cacheitem.getValue(javatype))
        else:
            result = self.__cacheitem.getValue(JavaInstancesFactory.get_java_instance("JsonObject"))
            if result is not None:
                return TypeCaster.deserialize(result, objtype, isjsonobject=True)

    def remove_cache_data_notification_listener(self, callablefunction: Callable, eventtypes):
        """
        Unregisters the user from cache data modification notifications.

        :param callablefunction: The callable function that is registered for notifications.
        :param eventtypes: List of Event types the listener is to be unregistered against.
        :type eventtypes: list
        """
        for eventtype in eventtypes:
            ValidateType.type_check(eventtype, EventType, self.remove_cache_data_notification_listener)
        ValidateType.params_check(callablefunction, 2, self.remove_cache_data_notification_listener)

        javaeventtypes = EventsListenerHelper.get_event_type_enum_set(eventtypes)
        listener = EventsListenerHelper.get_listener(callablefunction, CacheDataModificationListener)

        self.__cacheitem.removeCacheDataNotificationListener(listener, javaeventtypes)

    def set_cache_item_priority(self, priority):
        """
        Sets the CacheItemPriority of the cache item.

        :param priority: CacheItemPriority to be associated with cache item.
        :type priority: CacheItemPriority
        """
        ValidateType.type_check(priority, CacheItemPriority, self.set_cache_item_priority)
        priorityvalue = EnumUtil.get_cache_item_priority(priority.value)
        self.__cacheitem.setCacheItemPriority(priorityvalue)

    def set_cache_item_version(self, version):
        """
        Sets the CacheItemVersion of the cache item.

        :param version: CacheItemVersion value It is basically a numeric value that is used to represent the version
            of the cached item which changes
        :type version: CacheItemVersion
        """
        ValidateType.type_check(version, CacheItemVersion, self.set_cache_item_version)

        self.__cacheitem.setCacheItemVersion(JavaInstancesFactory.get_java_instance("CacheItemVersion")(version.get_version()))

    def set_dependency(self, dependency):
        """
        Sets CacheDependency of CacheItem

        :param dependency: The Cache Dependency instance to be associated with cache item.
        :type dependency: CacheDependency
        """
        ValidateType.validate_instance(dependency, CacheDependency, self.set_dependency)

        self.__cacheitem.setDependency(dependency.get_instance())

    def set_expiration(self, expiration):
        """
        Sets the Expiration of the cache item.

        :param expiration: Expiration value This property sets Expiration for the cache item. After the specified
            timespan, the item expires from cache.
        :type expiration: Expiration
        """
        ValidateType.type_check(expiration, Expiration, self.set_expiration)
        self.__cacheitem.setExpiration(expiration.get_instance())

    def set_group(self, groupname):
        """
        Sets the group associated with the cache item. It can be queried on the basis of Groups.

        :param groupname: The group to be associated with cache item.
        :type groupname: str
        """
        ValidateType.is_string(groupname, self.set_group)
        self.__cacheitem.setGroup(TypeCaster.to_java_primitive_type(groupname))

    def set_named_tags(self, namedtags):
        """
        Sets NamedTags of CacheItem

        :param namedtags: NamedTags to be associated with cache item.
        :type namedtags: NamedTagsDictionary
        """
        ValidateType.type_check(namedtags, NamedTagsDictionary, self.set_named_tags)

        self.__cacheitem.setNamedTags(namedtags.get_instance())

    def set_resync_options(self, resyncoptions):
        """
        Sets ResyncOption of CacheItem

        :param resyncoptions: ResyncOptions specific to the cache item.
        :type resyncoptions: ResyncOptions
        """
        ValidateType.type_check(resyncoptions, ResyncOptions, self.set_resync_options)
        self.__cacheitem.setResyncOptions(resyncoptions.get_instance())

    def set_tags(self, tags):
        """
        Sets the tags information associated with the cache item, it can be queried on the basis of Tags provided.

        :param tags: List of Tags to be associated with cache item.
        :type tags: list
        """
        ValidateType.type_check(tags, list, self.get_tags)

        for tag in tags:
            ValidateType.type_check(tag, Tag, self.set_tags)

        self.__cacheitem.setTags(TypeCaster.to_java_array_list(tags))

    def set_value(self, value):
        """
        Sets the value of the cache item.

        :param value: Actual object to be stored in cache.
        :type value: object
        """
        ValidateType.is_none(value, self.set_value)

        if not isinstance(value, object):
            raise TypeError(f"{self.set_value.__name__} failed. Parameter \"value\" is not instance of object")

        javatype = TypeCaster.is_python_primitive(value)

        if javatype is not None:
            self.__cacheitem.setValue(javatype)
        else:
            self.__cacheitem.setValue(TypeCaster.serialize(value, isjsonobject=True))

Klassen

class CacheItem (value=None)

NCache verwendet eine „Schlüssel“- und „Wert“-Struktur zum Speichern von Objekten im Cache. Wenn ein Objekt zum Cache hinzugefügt wird, wird es als Wert und Metadaten für den angegebenen Schlüssel gespeichert. Diese Kombination aus Wert und Metadaten wird in als CacheItem definiert NCache. Der Wert der im Cache gespeicherten Objekte kann von einfachen Zeichenfolgetypen bis hin zu komplexen Objekten reichen. CacheItem-Klasse in NCache verfügt über Eigenschaften, mit denen Sie Metadaten für das Element festlegen können, das auf organisierte Weise zum Cache hinzugefügt werden soll. In Szenarien, in denen beim Hinzufügen eines Elements im Cache mehrere Attribute festgelegt werden müssen, wird die Verwendung von CacheItem bevorzugt. Durch die Verwendung des Klassenobjekts CacheItem wird das Problem der Verwendung mehrerer API-Überladungen beim Hinzufügen/Aktualisieren von Daten im Cache beseitigt. Sie können problemlos die grundlegende API-Überladung verwenden und hinzufügen /Aktualisieren Sie Daten einfach mit CacheItem.

Initialisieren Sie eine neue Instanz des Cache-Elements.

:param-Wert: Tatsächliches Objekt, das im Cache gespeichert werden soll. :Typwert: Objekt

Erweitern Sie den Quellcode
class CacheItem:
    """
    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.
    """
    def __init__(self, value=None):
        """
        Initialize new instance of cache item.

        :param value: Actual object to be stored in cache.
        :type value: object
        """

        if value is None:
            self.__cacheitem = JavaInstancesFactory.get_java_instance("CacheItem")()
        else:
            javatype = TypeCaster.is_python_primitive(value)
            if javatype is not None:
                self.__cacheitem = JavaInstancesFactory.get_java_instance("CacheItem")(javatype)
            else:
                self.__cacheitem = JavaInstancesFactory.get_java_instance("CacheItem")(TypeCaster.serialize(value, isjsonobject=True, verbose=True))

    def set_instance(self, value):
        self.__cacheitem = value

    def get_instance(self):
        return self.__cacheitem

    def add_cache_data_notification_listener(self, callablefunction, eventtypes, 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 against.

        :param callablefunction: Callable function to be invoked when an item is updated or removed. This
        function should follow this signature: callablefunction(key: str, eventarg: CacheEventArg)
        :type callablefunction: Callable
        :param eventtypes: List of Event types the listener is registered against.
        :type eventtypes: list
        :param datafilter: Tells whether to receive metadata, data with metadata or none when a notification is
            triggered.
        :type datafilter: EventDataFilter
        """
        ValidateType.params_check(callablefunction, 2, self.add_cache_data_notification_listener)
        for item in eventtypes:
            ValidateType.type_check(item, EventType, self.add_cache_data_notification_listener)
        ValidateType.type_check(datafilter, EventDataFilter, self.add_cache_data_notification_listener)

        eventlistener = EventsListenerHelper.get_listener(callablefunction, CacheDataModificationListener)
        javaeventtypes = EventsListenerHelper.get_event_type_enum_set(eventtypes)
        javadatafilter = EnumUtil.get_event_data_filter(datafilter.value)

        self.__cacheitem.addCacheDataNotificationListener(eventlistener, javaeventtypes, javadatafilter)

    def get_cache_item_priority(self):
        """
        Gets the relative priority for cache item which is kept under consideration whenever cache starts to free up
        space and evicts items.

        :return: CacheItemPriority associated with cache item.
        :rtype: CacheItemPriority
        """
        result = self.__cacheitem.getCacheItemPriority()

        enumtype = None
        if result is not None:
            enumtype = EnumUtil.get_cache_item_priority_value(result)

        return enumtype

    def get_cache_item_version(self):
        """
        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.

        :return: The version associated with the cache item.
        :rtype: CacheItemVersion
        """
        version = self.__cacheitem.getCacheItemVersion()

        if version is not None:
            version = CacheItemVersion(int(version.getVersion()))

        return version

    def get_creation_time(self):
        """
        Gets the time when the item was added in cache for the first time.

        :return: The date of creation of the cache item.
        :rtype: datetime
        """
        result = self.__cacheitem.getCreationTime()

        if result is not None:
            result = TypeCaster.to_python_date(result)

        return result

    def get_dependency(self):
        """
        Gets the Cache Dependency instance that contains all dependencies associated with cache item.

        :return: The Cache Dependency instance associated with cache item.
        :rtype: CacheDependency
        """
        result = self.__cacheitem.getDependency()
        dependencytype = EnumUtil.get_dependency_type_info(result)
        dependency = None

        if dependencytype == 1:
            dependency = KeyDependency("key")
            dependency.set_instance(result)
        elif dependencytype == 2:
            dependency = FileDependency("key")
            dependency.set_instance(result)
        elif dependencytype == 5:
            dependency = SqlCacheDependency("ConString", "CmdText")
            dependency.set_instance(result)
        elif dependencytype == 6:
            dependency = OracleCacheDependency("ConString", "CmdText")
            dependency.set_instance(result)
        else:
            dependency = CacheDependency()
            dependency.set_instance(result)

        return dependency

    def get_expiration(self):
        """
        Gets the expiration mechanism for cache item.

        :return: Expiration instance that contains info about cache item expiration mechanism.
        :rtype: Expiration
        """
        result = self.__cacheitem.getExpiration()

        if result is not None:
            expiration = Expiration()
            expiration.set_instance(result)
            return expiration

        return result

    def get_group(self):
        """
        Gets the group associated with the cache item. It can be queried on the basis of Groups.

        :return: The group associated with cache item.
        :rtype: str
        """
        result = self.__cacheitem.getGroup()

        if result is not None:
            result = TypeCaster.to_python_primitive_type(result)

        return result

    def get_last_modified_time(self):
        """
        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.

        :return: The last modification time of the cache item.
        :rtype: datetime
        """
        result = self.__cacheitem.getLastModifiedTime()

        if result is not None:
            timestamp = float(result.getTime())
            result = datetime.fromtimestamp(timestamp / 1000)

        return result

    def get_named_tags(self):
        """
        Gets the NamedTags information associated with the cache item, it can be queried on the basis of NamedTags
        provided.

        :return: NamedTags associated with cache item.
        :rtype: NamedTagsDictionary
        """
        result = self.__cacheitem.getNamedTags()

        if result is not None:
            obj = NamedTagsDictionary()
            obj.set_instance(result)
            return obj

        return result

    def get_resync_options(self):
        """
        Gets the ResyncOptions specific to the cache item.

        :return: ResyncOptions specific to the cache item.
        :rtype: ResyncOptions
        """
        result = self.__cacheitem.getResyncOptions()

        if result is not None:
            resyncoptions = ResyncOptions(False)
            resyncoptions.set_instance(result)
            return resyncoptions

        return result

    def get_tags(self):
        """
        Gets the tags information associated with the cache item, it can be queried on the basis of Tags provided.

        :return: List of Tags associated with cache item.
        :rtype: list
        """
        result = self.__cacheitem.getTags()
        if result is not None:
            result = TypeCaster.to_python_list(result, False, Tag("DummyTag"))
        return result

    def get_value(self, objtype):
        """
        Returns the value stored in the cache item.

        :param objtype: Specifies the type of value obtained from the cacheItem.
        :type objtype: type
        :return: Returns the value stored in the cache item.
        :rtype: object
        """
        ValidateType.type_check(objtype, type, self.get_value)

        pythontype, javatype = TypeCaster.is_java_primitive(objtype)

        if javatype is not None:
            return pythontype(self.__cacheitem.getValue(javatype))
        else:
            result = self.__cacheitem.getValue(JavaInstancesFactory.get_java_instance("JsonObject"))
            if result is not None:
                return TypeCaster.deserialize(result, objtype, isjsonobject=True)

    def remove_cache_data_notification_listener(self, callablefunction: Callable, eventtypes):
        """
        Unregisters the user from cache data modification notifications.

        :param callablefunction: The callable function that is registered for notifications.
        :param eventtypes: List of Event types the listener is to be unregistered against.
        :type eventtypes: list
        """
        for eventtype in eventtypes:
            ValidateType.type_check(eventtype, EventType, self.remove_cache_data_notification_listener)
        ValidateType.params_check(callablefunction, 2, self.remove_cache_data_notification_listener)

        javaeventtypes = EventsListenerHelper.get_event_type_enum_set(eventtypes)
        listener = EventsListenerHelper.get_listener(callablefunction, CacheDataModificationListener)

        self.__cacheitem.removeCacheDataNotificationListener(listener, javaeventtypes)

    def set_cache_item_priority(self, priority):
        """
        Sets the CacheItemPriority of the cache item.

        :param priority: CacheItemPriority to be associated with cache item.
        :type priority: CacheItemPriority
        """
        ValidateType.type_check(priority, CacheItemPriority, self.set_cache_item_priority)
        priorityvalue = EnumUtil.get_cache_item_priority(priority.value)
        self.__cacheitem.setCacheItemPriority(priorityvalue)

    def set_cache_item_version(self, version):
        """
        Sets the CacheItemVersion of the cache item.

        :param version: CacheItemVersion value It is basically a numeric value that is used to represent the version
            of the cached item which changes
        :type version: CacheItemVersion
        """
        ValidateType.type_check(version, CacheItemVersion, self.set_cache_item_version)

        self.__cacheitem.setCacheItemVersion(JavaInstancesFactory.get_java_instance("CacheItemVersion")(version.get_version()))

    def set_dependency(self, dependency):
        """
        Sets CacheDependency of CacheItem

        :param dependency: The Cache Dependency instance to be associated with cache item.
        :type dependency: CacheDependency
        """
        ValidateType.validate_instance(dependency, CacheDependency, self.set_dependency)

        self.__cacheitem.setDependency(dependency.get_instance())

    def set_expiration(self, expiration):
        """
        Sets the Expiration of the cache item.

        :param expiration: Expiration value This property sets Expiration for the cache item. After the specified
            timespan, the item expires from cache.
        :type expiration: Expiration
        """
        ValidateType.type_check(expiration, Expiration, self.set_expiration)
        self.__cacheitem.setExpiration(expiration.get_instance())

    def set_group(self, groupname):
        """
        Sets the group associated with the cache item. It can be queried on the basis of Groups.

        :param groupname: The group to be associated with cache item.
        :type groupname: str
        """
        ValidateType.is_string(groupname, self.set_group)
        self.__cacheitem.setGroup(TypeCaster.to_java_primitive_type(groupname))

    def set_named_tags(self, namedtags):
        """
        Sets NamedTags of CacheItem

        :param namedtags: NamedTags to be associated with cache item.
        :type namedtags: NamedTagsDictionary
        """
        ValidateType.type_check(namedtags, NamedTagsDictionary, self.set_named_tags)

        self.__cacheitem.setNamedTags(namedtags.get_instance())

    def set_resync_options(self, resyncoptions):
        """
        Sets ResyncOption of CacheItem

        :param resyncoptions: ResyncOptions specific to the cache item.
        :type resyncoptions: ResyncOptions
        """
        ValidateType.type_check(resyncoptions, ResyncOptions, self.set_resync_options)
        self.__cacheitem.setResyncOptions(resyncoptions.get_instance())

    def set_tags(self, tags):
        """
        Sets the tags information associated with the cache item, it can be queried on the basis of Tags provided.

        :param tags: List of Tags to be associated with cache item.
        :type tags: list
        """
        ValidateType.type_check(tags, list, self.get_tags)

        for tag in tags:
            ValidateType.type_check(tag, Tag, self.set_tags)

        self.__cacheitem.setTags(TypeCaster.to_java_array_list(tags))

    def set_value(self, value):
        """
        Sets the value of the cache item.

        :param value: Actual object to be stored in cache.
        :type value: object
        """
        ValidateType.is_none(value, self.set_value)

        if not isinstance(value, object):
            raise TypeError(f"{self.set_value.__name__} failed. Parameter \"value\" is not instance of object")

        javatype = TypeCaster.is_python_primitive(value)

        if javatype is not None:
            self.__cacheitem.setValue(javatype)
        else:
            self.__cacheitem.setValue(TypeCaster.serialize(value, isjsonobject=True))

Methoden

def add_cache_data_notification_listener(self, callablefunction, eventtypes, datafilter)

Damit können Sie Anwendungen benachrichtigen, wenn ihre Objekte aktualisiert oder aus dem Cache entfernt werden. Listener können für den/die Ereignistyp(en) für den Schlüssel registriert werden, gegen den die Elemente eingefügt werden.

:param callablefunction: Aufrufbare Funktion, die aufgerufen wird, wenn ein Element aktualisiert oder entfernt wird. Diese Funktion sollte dieser Signatur folgen: callablefunction(key: str, eventarg: CacheEventArg) :type callablefunction: Callable :param eventtypes: Liste der Ereignistypen, für die der Listener registriert ist. :type eventtypes: list :param datafilter: Gibt an, ob Metadaten, Daten mit Metadaten oder keine empfangen werden sollen, wenn eine Benachrichtigung ausgelöst wird. :Typ Datenfilter: EventDataFilter

Erweitern Sie den Quellcode
def add_cache_data_notification_listener(self, callablefunction, eventtypes, 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 against.

    :param callablefunction: Callable function to be invoked when an item is updated or removed. This
    function should follow this signature: callablefunction(key: str, eventarg: CacheEventArg)
    :type callablefunction: Callable
    :param eventtypes: List of Event types the listener is registered against.
    :type eventtypes: list
    :param datafilter: Tells whether to receive metadata, data with metadata or none when a notification is
        triggered.
    :type datafilter: EventDataFilter
    """
    ValidateType.params_check(callablefunction, 2, self.add_cache_data_notification_listener)
    for item in eventtypes:
        ValidateType.type_check(item, EventType, self.add_cache_data_notification_listener)
    ValidateType.type_check(datafilter, EventDataFilter, self.add_cache_data_notification_listener)

    eventlistener = EventsListenerHelper.get_listener(callablefunction, CacheDataModificationListener)
    javaeventtypes = EventsListenerHelper.get_event_type_enum_set(eventtypes)
    javadatafilter = EnumUtil.get_event_data_filter(datafilter.value)

    self.__cacheitem.addCacheDataNotificationListener(eventlistener, javaeventtypes, javadatafilter)
def get_cache_item_priority(self)

Ruft die relative Priorität für Cache-Elemente ab, die immer dann berücksichtigt wird, wenn der Cache beginnt, Speicherplatz freizugeben und Elemente zu entfernen.

:return: CacheItemPriority, die dem Cache-Element zugeordnet ist. :rtype: CacheItemPriority

Erweitern Sie den Quellcode
def get_cache_item_priority(self):
    """
    Gets the relative priority for cache item which is kept under consideration whenever cache starts to free up
    space and evicts items.

    :return: CacheItemPriority associated with cache item.
    :rtype: CacheItemPriority
    """
    result = self.__cacheitem.getCacheItemPriority()

    enumtype = None
    if result is not None:
        enumtype = EnumUtil.get_cache_item_priority_value(result)

    return enumtype
def get_cache_item_version(self)

Ruft die mit dem Cache-Element verknüpfte Version ab. Version ist im Grunde ein numerischer Wert, der zur Darstellung der Version des zwischengespeicherten Elements verwendet wird, die sich bei jeder Aktualisierung eines Elements ändert.

:return: Die mit dem Cache-Element verknüpfte Version. :rtype: CacheItemVersion

Erweitern Sie den Quellcode
def get_cache_item_version(self):
    """
    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.

    :return: The version associated with the cache item.
    :rtype: CacheItemVersion
    """
    version = self.__cacheitem.getCacheItemVersion()

    if version is not None:
        version = CacheItemVersion(int(version.getVersion()))

    return version
def get_creation_time(self)

Ruft die Zeit ab, zu der das Element zum ersten Mal zum Cache hinzugefügt wurde.

:return: Das Erstellungsdatum des Cache-Elements. :rtype: datetime

Erweitern Sie den Quellcode
def get_creation_time(self):
    """
    Gets the time when the item was added in cache for the first time.

    :return: The date of creation of the cache item.
    :rtype: datetime
    """
    result = self.__cacheitem.getCreationTime()

    if result is not None:
        result = TypeCaster.to_python_date(result)

    return result
def get_dependency(self)

Ruft die Cache-Abhängigkeitsinstanz ab, die alle mit dem Cache-Element verknüpften Abhängigkeiten enthält.

:return: Die Cache-Abhängigkeitsinstanz, die dem Cache-Element zugeordnet ist. :rtype: CacheDependency

Erweitern Sie den Quellcode
def get_dependency(self):
    """
    Gets the Cache Dependency instance that contains all dependencies associated with cache item.

    :return: The Cache Dependency instance associated with cache item.
    :rtype: CacheDependency
    """
    result = self.__cacheitem.getDependency()
    dependencytype = EnumUtil.get_dependency_type_info(result)
    dependency = None

    if dependencytype == 1:
        dependency = KeyDependency("key")
        dependency.set_instance(result)
    elif dependencytype == 2:
        dependency = FileDependency("key")
        dependency.set_instance(result)
    elif dependencytype == 5:
        dependency = SqlCacheDependency("ConString", "CmdText")
        dependency.set_instance(result)
    elif dependencytype == 6:
        dependency = OracleCacheDependency("ConString", "CmdText")
        dependency.set_instance(result)
    else:
        dependency = CacheDependency()
        dependency.set_instance(result)

    return dependency
def get_expiration(self)

Ruft den Ablaufmechanismus für das Cache-Element ab.

:return: Ablaufinstanz, die Informationen zum Ablaufmechanismus für Cache-Elemente enthält. :rtype: Ablauf

Erweitern Sie den Quellcode
def get_expiration(self):
    """
    Gets the expiration mechanism for cache item.

    :return: Expiration instance that contains info about cache item expiration mechanism.
    :rtype: Expiration
    """
    result = self.__cacheitem.getExpiration()

    if result is not None:
        expiration = Expiration()
        expiration.set_instance(result)
        return expiration

    return result
def get_group(self)

Ruft die dem Cache-Element zugeordnete Gruppe ab. Es kann auf Basis von Gruppen abgefragt werden.

:return: Die dem Cache-Element zugeordnete Gruppe. :rtype: str

Erweitern Sie den Quellcode
def get_group(self):
    """
    Gets the group associated with the cache item. It can be queried on the basis of Groups.

    :return: The group associated with cache item.
    :rtype: str
    """
    result = self.__cacheitem.getGroup()

    if result is not None:
        result = TypeCaster.to_python_primitive_type(result)

    return result
def get_instance(self)
Erweitern Sie den Quellcode
def get_instance(self):
    return self.__cacheitem
def get_last_modified_time(self)

Ruft die lastModifiedTime des Cache-Elements ab. CacheItem speichert die letzte Änderungszeit des Cache-Elements. Wenn ein Element im Cache aktualisiert wird, wird auch seine letzte Änderungszeit aktualisiert. Der Zeitpunkt der letzten Änderung wird überprüft, wenn die Räumung auf der Basis der „Letztstens zuletzt verwendet“ ausgelöst wird.

:return: Die letzte Änderungszeit des Cache-Elements. :rtype: datetime

Erweitern Sie den Quellcode
def get_last_modified_time(self):
    """
    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.

    :return: The last modification time of the cache item.
    :rtype: datetime
    """
    result = self.__cacheitem.getLastModifiedTime()

    if result is not None:
        timestamp = float(result.getTime())
        result = datetime.fromtimestamp(timestamp / 1000)

    return result
def get_named_tags(self)

Ruft die NamedTags-Informationen ab, die dem Cache-Element zugeordnet sind. Sie können auf der Grundlage der bereitgestellten NamedTags abgefragt werden.

:return: NamedTags, die dem Cache-Element zugeordnet sind. :rtype: NamedTagsDictionary

Erweitern Sie den Quellcode
def get_named_tags(self):
    """
    Gets the NamedTags information associated with the cache item, it can be queried on the basis of NamedTags
    provided.

    :return: NamedTags associated with cache item.
    :rtype: NamedTagsDictionary
    """
    result = self.__cacheitem.getNamedTags()

    if result is not None:
        obj = NamedTagsDictionary()
        obj.set_instance(result)
        return obj

    return result
def get_resync_options(self)

Ruft die für das Cache-Element spezifischen ResyncOptions ab.

:return: Für das Cache-Element spezifische ResyncOptions. :rtype: ResyncOptions

Erweitern Sie den Quellcode
def get_resync_options(self):
    """
    Gets the ResyncOptions specific to the cache item.

    :return: ResyncOptions specific to the cache item.
    :rtype: ResyncOptions
    """
    result = self.__cacheitem.getResyncOptions()

    if result is not None:
        resyncoptions = ResyncOptions(False)
        resyncoptions.set_instance(result)
        return resyncoptions

    return result
def get_tags(self)

Ruft die mit dem Cache-Element verknüpften Tag-Informationen ab und kann auf Basis der bereitgestellten Tags abgefragt werden.

:return: Liste der Tags, die dem Cache-Element zugeordnet sind. :rtype: Liste

Erweitern Sie den Quellcode
def get_tags(self):
    """
    Gets the tags information associated with the cache item, it can be queried on the basis of Tags provided.

    :return: List of Tags associated with cache item.
    :rtype: list
    """
    result = self.__cacheitem.getTags()
    if result is not None:
        result = TypeCaster.to_python_list(result, False, Tag("DummyTag"))
    return result
def get_value(self, objtype)

Gibt den im Cache-Element gespeicherten Wert zurück.

:param objtype: Gibt den Typ des vom CacheItem erhaltenen Werts an. :type objtype: type :return: Gibt den im Cache-Element gespeicherten Wert zurück. :rtype: Objekt

Erweitern Sie den Quellcode
def get_value(self, objtype):
    """
    Returns the value stored in the cache item.

    :param objtype: Specifies the type of value obtained from the cacheItem.
    :type objtype: type
    :return: Returns the value stored in the cache item.
    :rtype: object
    """
    ValidateType.type_check(objtype, type, self.get_value)

    pythontype, javatype = TypeCaster.is_java_primitive(objtype)

    if javatype is not None:
        return pythontype(self.__cacheitem.getValue(javatype))
    else:
        result = self.__cacheitem.getValue(JavaInstancesFactory.get_java_instance("JsonObject"))
        if result is not None:
            return TypeCaster.deserialize(result, objtype, isjsonobject=True)
def remove_cache_data_notification_listener(self, callablefunction: Callable, eventtypes)

Hebt die Registrierung des Benutzers für Benachrichtigungen über Cache-Datenänderungen auf.

:param callablefunction: Die aufrufbare Funktion, die für Benachrichtigungen registriert ist. :param eventtypes: Liste der Ereignistypen, für die die Registrierung des Listeners aufgehoben werden soll. :type eventtypes: Liste

Erweitern Sie den Quellcode
def remove_cache_data_notification_listener(self, callablefunction: Callable, eventtypes):
    """
    Unregisters the user from cache data modification notifications.

    :param callablefunction: The callable function that is registered for notifications.
    :param eventtypes: List of Event types the listener is to be unregistered against.
    :type eventtypes: list
    """
    for eventtype in eventtypes:
        ValidateType.type_check(eventtype, EventType, self.remove_cache_data_notification_listener)
    ValidateType.params_check(callablefunction, 2, self.remove_cache_data_notification_listener)

    javaeventtypes = EventsListenerHelper.get_event_type_enum_set(eventtypes)
    listener = EventsListenerHelper.get_listener(callablefunction, CacheDataModificationListener)

    self.__cacheitem.removeCacheDataNotificationListener(listener, javaeventtypes)
def set_cache_item_priority(self, priority)

Legt die CacheItemPriority des Cache-Elements fest.

:param Priority: CacheItemPriority, die dem Cache-Element zugeordnet werden soll. :Typpriorität: CacheItemPriority

Erweitern Sie den Quellcode
def set_cache_item_priority(self, priority):
    """
    Sets the CacheItemPriority of the cache item.

    :param priority: CacheItemPriority to be associated with cache item.
    :type priority: CacheItemPriority
    """
    ValidateType.type_check(priority, CacheItemPriority, self.set_cache_item_priority)
    priorityvalue = EnumUtil.get_cache_item_priority(priority.value)
    self.__cacheitem.setCacheItemPriority(priorityvalue)
def set_cache_item_version(self, version)

Legt die CacheItemVersion des Cache-Elements fest.

:param version: CacheItemVersion value Es handelt sich im Grunde um einen numerischen Wert, der verwendet wird, um die Version des zwischengespeicherten Elements darzustellen, das sich ändert :type version: CacheItemVersion

Erweitern Sie den Quellcode
def set_cache_item_version(self, version):
    """
    Sets the CacheItemVersion of the cache item.

    :param version: CacheItemVersion value It is basically a numeric value that is used to represent the version
        of the cached item which changes
    :type version: CacheItemVersion
    """
    ValidateType.type_check(version, CacheItemVersion, self.set_cache_item_version)

    self.__cacheitem.setCacheItemVersion(JavaInstancesFactory.get_java_instance("CacheItemVersion")(version.get_version()))
def set_dependency(self, dependency)

Legt die CacheDependency von CacheItem fest

:param-Abhängigkeit: Die Cache-Abhängigkeitsinstanz, die dem Cache-Element zugeordnet werden soll. :Typabhängigkeit: CacheDependency

Erweitern Sie den Quellcode
def set_dependency(self, dependency):
    """
    Sets CacheDependency of CacheItem

    :param dependency: The Cache Dependency instance to be associated with cache item.
    :type dependency: CacheDependency
    """
    ValidateType.validate_instance(dependency, CacheDependency, self.set_dependency)

    self.__cacheitem.setDependency(dependency.get_instance())
def set_expiration(self, expiration)

Legt den Ablauf des Cache-Elements fest.

:param expiration: Ablaufwert Diese Eigenschaft legt den Ablaufwert für das Cache-Element fest. Nach der angegebenen Zeitspanne läuft das Element aus dem Cache ab. :Typ Ablauf: Ablauf

Erweitern Sie den Quellcode
def set_expiration(self, expiration):
    """
    Sets the Expiration of the cache item.

    :param expiration: Expiration value This property sets Expiration for the cache item. After the specified
        timespan, the item expires from cache.
    :type expiration: Expiration
    """
    ValidateType.type_check(expiration, Expiration, self.set_expiration)
    self.__cacheitem.setExpiration(expiration.get_instance())
def set_group(self, groupname)

Legt die mit dem Cache-Element verknüpfte Gruppe fest. Es kann auf Basis von Gruppen abgefragt werden.

:param Gruppenname: Die Gruppe, die dem Cache-Element zugeordnet werden soll. :Gruppenname eingeben: str

Erweitern Sie den Quellcode
def set_group(self, groupname):
    """
    Sets the group associated with the cache item. It can be queried on the basis of Groups.

    :param groupname: The group to be associated with cache item.
    :type groupname: str
    """
    ValidateType.is_string(groupname, self.set_group)
    self.__cacheitem.setGroup(TypeCaster.to_java_primitive_type(groupname))
def set_instance(self, value)
Erweitern Sie den Quellcode
def set_instance(self, value):
    self.__cacheitem = value
def set_named_tags(self, namedtags)

Legt NamedTags von CacheItem fest

:param namedtags: NamedTags, die dem Cache-Element zugeordnet werden sollen. :namedtags eingeben: NamedTagsDictionary

Erweitern Sie den Quellcode
def set_named_tags(self, namedtags):
    """
    Sets NamedTags of CacheItem

    :param namedtags: NamedTags to be associated with cache item.
    :type namedtags: NamedTagsDictionary
    """
    ValidateType.type_check(namedtags, NamedTagsDictionary, self.set_named_tags)

    self.__cacheitem.setNamedTags(namedtags.get_instance())
def set_resync_options(self, resyncoptions)

Legt die ResyncOption von CacheItem fest

:param resyncoptions: ResyncOptions speziell für das Cache-Element. :type resyncoptions: ResyncOptions

Erweitern Sie den Quellcode
def set_resync_options(self, resyncoptions):
    """
    Sets ResyncOption of CacheItem

    :param resyncoptions: ResyncOptions specific to the cache item.
    :type resyncoptions: ResyncOptions
    """
    ValidateType.type_check(resyncoptions, ResyncOptions, self.set_resync_options)
    self.__cacheitem.setResyncOptions(resyncoptions.get_instance())
def set_tags(self, tags)

Legt die mit dem Cache-Element verknüpften Tag-Informationen fest. Es kann auf der Grundlage der bereitgestellten Tags abgefragt werden.

:param-Tags: Liste der Tags, die dem Cache-Element zugeordnet werden sollen. :Typ-Tags: Liste

Erweitern Sie den Quellcode
def set_tags(self, tags):
    """
    Sets the tags information associated with the cache item, it can be queried on the basis of Tags provided.

    :param tags: List of Tags to be associated with cache item.
    :type tags: list
    """
    ValidateType.type_check(tags, list, self.get_tags)

    for tag in tags:
        ValidateType.type_check(tag, Tag, self.set_tags)

    self.__cacheitem.setTags(TypeCaster.to_java_array_list(tags))
def set_value(self, value)

Legt den Wert des Cache-Elements fest.

:param-Wert: Tatsächliches Objekt, das im Cache gespeichert werden soll. :Typwert: Objekt

Erweitern Sie den Quellcode
def set_value(self, value):
    """
    Sets the value of the cache item.

    :param value: Actual object to be stored in cache.
    :type value: object
    """
    ValidateType.is_none(value, self.set_value)

    if not isinstance(value, object):
        raise TypeError(f"{self.set_value.__name__} failed. Parameter \"value\" is not instance of object")

    javatype = TypeCaster.is_python_primitive(value)

    if javatype is not None:
        self.__cacheitem.setValue(javatype)
    else:
        self.__cacheitem.setValue(TypeCaster.serialize(value, isjsonobject=True))