모듈 ncache.client.Cache

소스 코드 확장
import asyncio
import collections
from asyncio import Task
from typing import Type

from ncache.client.CacheItem import CacheItem
from ncache.client.CacheItemAttributes import CacheItemAttributes
from ncache.client.datastructures.DataStructureManager import DataStructureManager
from ncache.client.services.SearchService import SearchService
from ncache.client.services.MessagingService import MessagingService
from ncache.client.services.NotificationService import NotificationService
from ncache.client.CacheItemVersion import CacheItemVersion
from ncache.runtime.WriteThruOptions import WriteThruOptions
from ncache.runtime.ReadThruOptions import ReadThruOptions
from ncache.client.LockHandle import LockHandle
from ncache.runtime.util.TimeSpan import TimeSpan
from ncache.util.ExceptionHandler import ExceptionHandler
from ncache.util.JavaInstancesFactory import *
from ncache.util.TypeCaster import TypeCaster
from ncache.util.ValidateType import ValidateType
from ncache.runtime.util.Iterator import Iterator


class Cache:
        """
        This class contains the services and methods that are used to perform operations on the cache.
        """
        def __init__(self, cache):
                """
                This function gets an instance of the Cache
                :param cache: Instance of the Cache.
                """
                self.__cache = cache

        def __str__(self):
                result = self.__cache.toString()

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

        def get_instance(self):
                return self.__cache

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

        def get_count(self):
                """
                Gets the number of items stored in the cache

                :return: The number of items stored in the cache.
                :rtype: int
                """
                result = self.__cache.getCount()

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

                return result

        def get_notification_service(self):
                """
                Gets an instance of NotificationService

                :return: An instance of NotificationService
                :rtype: NotificationService
                """

                result = self.__cache.getNotificationService()

                if result is not None:
                        result = NotificationService(result)

                return result

        def get_messaging_service(self):
                """
                Gets an instance of MessagingService

                :return: An instance of MessagingService
                :rtype: MessagingService
                """
                result = self.__cache.getMessagingService()

                if result is not None:
                        result = MessagingService(result)

                return result

        def get_search_service(self):
                """
                Gets an instance of SearchService.

                :return: An instance of SearchService
                :rtype: SearchService
                """
                result = self.__cache.getSearchService()

                if result is not None:
                        result = SearchService(result)

                return result

        def get_data_structures_manager(self):
                """
                Gets an instance of DataStructureManager.

                :return: An instance of DataStructureManager
                :rtype: DataStructureManager
                """
                result = self.__cache.getDataStructuresManager()

                if result is not None:
                        result = DataStructureManager(result)

                return result

        def add(self, key, item, writethruoptions=None):
                """
                Adds an item or CacheItem into the Cache object with a cache key to reference its location. You can also
                specify WriteThruOptions

                :param key: Unique key to identify the cache item.
                :type key: str
                :param item: The item (object) or CacheItem to be stored in the cache.
                :type item: object or CacheItem
                :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either
                :type writethruoptions: WriteThruOptions
                :return: Represents the version of each cache item.
                :rtype: CacheItemVersion
                """

                ValidateType.is_key_value_valid(key, item, self.add)
                if writethruoptions is not None:
                        ValidateType.type_check(writethruoptions, WriteThruOptions, self.add)

                javatype = TypeCaster.is_python_primitive(item)
                javakey = TypeCaster.to_java_primitive_type(key)
                if javatype is not None:
                        if writethruoptions is None:
                                res = self.__cache.add(javakey, javatype)
                        else:
                                raise TypeError(ExceptionHandler.get_invalid_cache_add_exception_message(CacheItem))

                elif isinstance(item, CacheItem):
                        if writethruoptions is None:
                                res = self.__cache.add(javakey, item.get_instance())
                        else:
                                res = self.__cache.add(javakey, item.get_instance(), writethruoptions.get_instance())
                else:
                        if writethruoptions is None:
                                res = self.__cache.add(javakey, TypeCaster.serialize(item, isjsonobject=True))
                        else:
                                raise TypeError(ExceptionHandler.get_invalid_cache_add_exception_message(CacheItem))

                if res is not None:
                        return CacheItemVersion(int(res.getVersion()))

        def add_bulk(self, items, writethruoptions=None):
                """
                Adds a Dictionary of cache keys with CacheItem to the cache. You can also specify WriteThruOptions

                :param items: Dictionary of keys and CacheItem. Keys must be unique.
                :type items: dict
                :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WriteThru, WriteBehind or None.
                :type writethruoptions: WriteThruOptions
                :return: Dictionary of Keys along with Exception for items that were unable to store in cache.
                :rtype: dict
                """
                ValidateType.type_check(items, dict, self.add_bulk)
                for item in items:
                        ValidateType.is_string(item, self.add_bulk)
                        ValidateType.type_check(items[item], CacheItem, self.add_bulk)
                javaitems = TypeCaster.to_java_hash_map(items, False)

                if writethruoptions is not None:
                        ValidateType.type_check(writethruoptions, WriteThruOptions, self.add_bulk)
                        javawritethruoptions = writethruoptions.get_instance()

                        result = self.__cache.addBulk(javaitems, javawritethruoptions)
                else:
                        result = self.__cache.addBulk(javaitems)

                if result is not None:
                        return self.__bulk_result_to_dict(result, True)

        def add_async(self, key, item, writethruoptions=None):
                """
                Adds an item or a CacheItem to the cache asynchronously with a cache key to reference its location and with or without WriteThruOptions.

                :param key: Unique key to identify the cache item.
                :type key: str
                :param item: The item (object) or CacheItem to be stored in the cache.
                :type item: object
                :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either
                :type writethruoptions: WriteThruOptions
                :return: Task that performs an add operation in the background.
                :rtype: Task
                """
                return asyncio.create_task(self.__return_coroutine(self.add, key, item, writethruoptions))

        def insert(self, key, item, writethruoptions=None, lockhandle=None, releaselock=None):
                """
                Inserts an item or a CacheItem to the cache.

                :param key: Unique key to identify the cache item.
                :type key: str
                :param item: The value or the CacheItem that is to be inserted into the cache.
                :type item: object or CacheItem
                :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WriteThru, WriteBehind or None.
                :type writethruoptions: WriteThruOptions
                :param lockhandle: An instance of LockHandle that holds the lock information. If the item is locked, then it can only be updated if the correct lockHandle is specified.
                :type lockhandle: LockHandle
                :param releaselock: A flag to determine whether or not the lock should be released after operation is performed.
                :type releaselock: bool
                :return: Represents the version of each cache item.
                :rtype: CacheItemVersion
                """

                ValidateType.is_key_value_valid(key, item, self.insert)
                if writethruoptions is not None:
                        ValidateType.type_check(writethruoptions, WriteThruOptions, self.insert)

                if lockhandle is not None and releaselock is not None:
                        ValidateType.type_check(lockhandle, LockHandle, self.insert)
                        ValidateType.type_check(releaselock, bool, self.insert)

                javatype = TypeCaster.is_python_primitive(item)

                javakey = TypeCaster.to_java_primitive_type(key)

                if javatype is not None:
                        if writethruoptions is not None or lockhandle is not None or releaselock is not None:
                                raise TypeError(ExceptionHandler.get_invalid_cache_insert_exception_message(CacheItem))
                        res = self.__cache.insert(javakey, javatype)

                elif isinstance(item, CacheItem):
                        value = item.get_instance()

                        if lockhandle is not None and releaselock is not None:
                                javawritethruoptions = None
                                
                                if writethruoptions is not None:
                                        javawritethruoptions = writethruoptions.get_instance()
                                
                                javalockhandle = lockhandle.get_instance()
                                javareleaselock = TypeCaster.to_java_primitive_type(releaselock)
                                res = self.__cache.insert(javakey, value, javawritethruoptions, javalockhandle, javareleaselock)

                        elif lockhandle is not None or releaselock is not None:
                                raise ValueError(ExceptionHandler.exceptionmessages.get("Cache.insert"))

                        else:
                                javawritethruoptions = None
                                
                                if writethruoptions is not None:
                                        javawritethruoptions = writethruoptions.get_instance()
                                        
                                res = self.__cache.insert(javakey, value, javawritethruoptions)

                else:
                        if writethruoptions is not None or lockhandle is not None or releaselock is not None:
                                raise ValueError(ExceptionHandler.exceptionmessages.get("Cache.insert"))
                        value = TypeCaster.serialize(item, isjsonobject=True, verbose=True)
                        res = self.__cache.insert(javakey, value)

                if res is not None:
                        return CacheItemVersion(int(res.getVersion()))

        def insert_bulk(self, items, writethruoptions=None):
                """
                Inserts a Dictionary of cache keys with CacheItem to the cache with or without the WriteThruOptions.

                :param items: Dictionary of keys and CacheItem. Keys must be unique.
                :type items: dict
                :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WriteThru, WriteBehind or None.
                :type writethruoptions: WriteThruOptions
                :return: Dictionary of Keys along with Exception for items that were unable to store in cache.
                :rtype: dict
                """
                ValidateType.type_check(items, dict, self.insert_bulk)
                for item in items:
                        ValidateType.is_string(item, self.insert_bulk)
                        ValidateType.type_check(items[item], CacheItem, self.insert_bulk)
                javaitems = TypeCaster.to_java_hash_map(items, False)

                if writethruoptions is not None:
                        ValidateType.type_check(writethruoptions, WriteThruOptions, self.insert_bulk)
                        javawritethruoptions = writethruoptions.get_instance()

                        result = self.__cache.insertBulk(javaitems, javawritethruoptions)
                else:
                        result = self.__cache.insertBulk(javaitems)

                if result is not None:
                        return self.__bulk_result_to_dict(result, True)

        def insert_async(self, key, item, writethruoptions=None):
                """
                Inserts an item or a CacheItem to the cache asynchronously with a cache key to reference its location and with or without WriteThruOptions.

                :param key: Unique key to identify the cache item.
                :type key: str
                :param item: The item (object) or CacheItem to be stored in the cache.
                :type item: object
                :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WriteThru, WriteBehind or None.
                :type writethruoptions: WriteThruOptions
                :return: Task that performs an insert operation in the background.
                :rtype: Task
                """
                return asyncio.create_task(self.__return_coroutine(self.insert, key, item, writethruoptions))

        def update_attributes(self, key, attributes):
                """
                Update CacheItemAttributes of an existing item in cache.

                :param key: Unique key to identify the cache item.
                :type key: str
                :param attributes: An instance of CacheItemAttributes to update item in the cache.
                :type attributes: CacheItemAttributes
                :return: Flag that determines status of the update operation. True if attributes of the item in cache was updated successfully otherwise False.
                :rtype: bool
                """
                ValidateType.is_string(key, self.update_attributes)
                ValidateType.type_check(attributes, CacheItemAttributes, self.update_attributes)

                javakey = TypeCaster.to_java_primitive_type(key)
                javaattributes = attributes.get_instance()

                result = self.__cache.updateAttributes(javakey, javaattributes)

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

                return result

        def get(self, key, objtype, readthruoptions=None, cacheitemversion=None, acquirelock=None, locktimeout=None, lockhandle=None):
                """
                Retrieves the specified item from the Cache object.

                :param key: Unique key to identify the cache item.
                :type key: str
                :param objtype: Type of the item to be retrieved from cache
                :type objtype: type
                :param readthruoptions: ReadThruOptions to read from data source. These can be either ReadThru, ReadThruForced or None.
                :type readthruoptions: ReadThruOptions
                :param acquirelock: A flag to determine whether to acquire a lock or not.
                :type acquirelock: bool
                :param locktimeout: The TimeSpan after which the lock is automatically released.
                :type locktimeout: TimeSpan
                :param lockhandle: An instance of LockHandle to hold the lock information.
                :type lockhandle: LockHandle
                :param cacheitemversion: The version of the object. If None is passed for CacheItemVersion, then the version of the object from the cache is returned. If non-None CacheItemVersion is passed, then object is returned from the cache only if that is the current version of the object in the cache.
                :type cacheitemversion: CacheItemVersion
                :return: The retrieved cache item, or a None reference if the key is not found.
                :rtype: object
                """

                ValidateType.is_string(key, self.get)
                javakey = TypeCaster.to_java_primitive_type(key)

                ValidateType.type_check(objtype, type, self.get)

                if readthruoptions is not None:
                        ValidateType.type_check(readthruoptions, ReadThruOptions, self.get)

                if locktimeout is not None and lockhandle is not None and acquirelock is not None:
                        ValidateType.type_check(lockhandle, LockHandle, self.get)
                        ValidateType.type_check(locktimeout, TimeSpan, self.get)
                        ValidateType.type_check(acquirelock, bool, self.get)

                if cacheitemversion is not None:
                        ValidateType.type_check(cacheitemversion, CacheItemVersion, self.get)

                pythontype, javatype = TypeCaster.is_java_primitive(objtype)

                usejsonconversoin = False
                if javatype is None:
                        if isinstance(objtype(), collections.Collection):
                                javatype = JavaInstancesFactory.get_java_instance("JsonArray")
                        else:
                                javatype = JavaInstancesFactory.get_java_instance("JsonObject")
                        usejsonconversoin = True
                
                if cacheitemversion is not None:
                        javacacheitemversion = cacheitemversion.get_instance()
                        javareadthruoptions = None
                        
                        if readthruoptions is not None:
                                javareadthruoptions = readthruoptions.get_instance()

                        result = self.__cache.get(javakey, javacacheitemversion, javareadthruoptions, javatype)

                elif locktimeout is not None and lockhandle is not None and acquirelock is not None:
                        javalockhandle = lockhandle.get_instance()
                        javalocktimeout = locktimeout.get_instance()
                        javaacquirelock = TypeCaster.to_java_primitive_type(acquirelock)
                        result = self.__cache.get(javakey, javaacquirelock, javalocktimeout, javalockhandle, javatype)

                elif locktimeout is None and lockhandle is None and acquirelock is None and cacheitemversion is None:
                        javareadthruoptions = None
                        
                        if readthruoptions is not None:
                                javareadthruoptions = readthruoptions.get_instance()

                        result = self.__cache.get(javakey, javareadthruoptions, javatype)

                else:
                        raise ValueError(ExceptionHandler.exceptionmessages.get("Cache.get"))

                if result is not None:
                        if not usejsonconversoin:
                                result = pythontype(result)
                        else:
                                result = TypeCaster.deserialize(result, objtype, isjsonobject=True)
                return result

        def get_bulk(self, keys, objtype, readthruoptions=None):
                """
                Retrieves the objects from cache for the given keys as key-value pairs in form of a Dictionary.

                :param keys: The list keys against which items are to be fetched from cache.
                :type keys: list
                :param objtype: Type of the item to be retrieved from cache
                :type objtype: type
                :param readthruoptions: ReadThruOptions to read from data source. These can be either ReadThru, ReadThruForced or None.
                :type readthruoptions: ReadThruOptions
                :return: The retrieved cache items as Dictionary of key-value pairs.
                :rtype: dict
                """
                ValidateType.type_check(objtype, type, self.get_bulk)
                ValidateType.type_check(keys, list, self.get_bulk)
                for key in keys:
                        ValidateType.is_string(key, self.get_bulk)
                javakeys = TypeCaster.to_java_array_list(keys, True)

                pythontype, javatype = TypeCaster.is_java_primitive(objtype)

                if javatype is None:
                        javatype = JavaInstancesFactory.get_java_instance("JsonObject")

                javareadthruoptions = None

                if readthruoptions is not None:
                        ValidateType.type_check(readthruoptions, ReadThruOptions, self.get_bulk)
                        javareadthruoptions = readthruoptions.get_instance()

                result = self.__cache.getBulk(javakeys, javareadthruoptions, javatype)

                if result is not None:
                        return self.__bulk_result_to_dict(result, False, objtype)

        def get_cacheitem(self, key, readthruoptions=None, cacheitemversion=None, acquirelock=None, locktimeout=None, lockhandle=None):
                """
                Retrieves the specified CacheItem from the Cache object.

                :param key: Unique key to identify the cache item.
                :type key: str
                :param readthruoptions: ReadThruOptions to read from data source. These can be either ReadThru, ReadThruForced or None.
                :type readthruoptions: ReadThruOptions
                :param acquirelock: A flag to determine whether to acquire a lock or not.
                :type acquirelock: bool
                :param locktimeout: The TimeSpan after which the lock is automatically released.
                :type locktimeout: TimeSpan
                :param lockhandle: An instance of LockHandle to hold the lock information.
                :type lockhandle: LockHandle
                :param cacheitemversion: The version of the object. If None is passed for CacheItemVersion, then the version of
                        the object from the cache is returned. If non-None CacheItemVersion is passed, then object is returned from
                        the cache only if that is the current version of the object in the cache.
                :type cacheitemversion: CacheItemVersion
                :return: The retrieved CacheItem, or a None reference if the key is not found.
                :rtype: CacheItem
                """
                ValidateType.is_string(key, self.get_cacheitem)
                javakey = TypeCaster.to_java_primitive_type(key)
                if readthruoptions is not None:
                        ValidateType.type_check(readthruoptions, ReadThruOptions, self.get_cacheitem)

                if cacheitemversion is not None:
                        ValidateType.type_check(cacheitemversion, CacheItemVersion, self.get_cacheitem)

                if acquirelock is not None and lockhandle is not None and locktimeout is not None:
                        ValidateType.type_check(acquirelock, bool, self.get_cacheitem)
                        ValidateType.type_check(lockhandle, LockHandle, self.get_cacheitem)
                        ValidateType.type_check(locktimeout, TimeSpan, self.get_cacheitem)

                if cacheitemversion is not None:
                        javareadthruoptions = None
                        
                        if readthruoptions is not None:
                                javareadthruoptions = readthruoptions.get_instance()

                        javacacheitemversion = cacheitemversion.get_instance()
                        result = self.__cache.getCacheItem(javakey, javacacheitemversion, javareadthruoptions)

                elif acquirelock is not None and lockhandle is not None and locktimeout is not None:
                        javaacquirelock = TypeCaster.to_java_primitive_type(acquirelock)
                        javalockhandle = lockhandle.get_instance()
                        javalocktimeout = locktimeout.get_instance()
                        result = self.__cache.getCacheItem(javakey, javaacquirelock, javalocktimeout, javalockhandle)

                elif cacheitemversion is None and acquirelock is None and lockhandle is None and locktimeout is None:
                        javareadthruoptions = None
                        
                        if readthruoptions is not None:
                                javareadthruoptions = readthruoptions.get_instance()

                        result = self.__cache.getCacheItem(javakey, javareadthruoptions)

                else:
                        raise ValueError(ExceptionHandler.exceptionmessages.get("Cache.get_cacheitem"))

                if result is not None:
                        cacheitem = CacheItem()
                        cacheitem.set_instance(result)
                        return cacheitem

                return result

        def get_cacheitem_bulk(self, keys, readthruoptions=None):
                """
                Retrieves the CacheItems from cache for the given keys as key-value pairs in form of a Dictionary.

                :param keys: The keys against which CacheItems are to be fetched from cache.
                :type keys: list
                :param readthruoptions: ReadThruOptions to read from data source. These can be either ReadThru, ReadThruForced or None.
                :type readthruoptions: ReadThruOptions
                :return: The retrieved CacheItems as Dictionary of key-value pairs.
                :rtype: dict
                """
                ValidateType.type_check(keys, list, self.get_cacheitem_bulk)
                for key in keys:
                        ValidateType.is_string(key, self.get_cacheitem_bulk)
                javakeys = TypeCaster.to_java_array_list(keys, True)

                if readthruoptions is not None:
                        ValidateType.type_check(readthruoptions, ReadThruOptions, self.get_cacheitem_bulk)
                        javareadthruoptions = readthruoptions.get_instance()
                        result = self.__cache.getCacheItemBulk(javakeys, javareadthruoptions)

                else:
                        result = self.__cache.getCacheItemBulk(javakeys)

                if result is not None:
                        return self.__bulk_result_to_dict(result, iscacheitem=True)

        def get_if_newer(self, key, cacheitemversion, objtype):
                """
                Gets an object from the cache only if a newer version of the object exists in cache.

                :param key: Unique key used to reference the desired object.
                :type key: str
                :param cacheitemversion: The CacheItemVersion of the object.
                :type cacheitemversion: CacheItemVersion
                :param objtype: Type of the item to be removed from cache
                :type objtype: type
                :return: If a newer object exists in the cache, the object is returned. Otherwise, None is returned.
                :rtype: object or None
                """
                ValidateType.is_string(key, self.get_if_newer)
                ValidateType.type_check(cacheitemversion, CacheItemVersion, self.get_if_newer)
                ValidateType.type_check(objtype, type, self.get_if_newer)

                javakey = TypeCaster.to_java_primitive_type(key)
                javacacheitemversion = cacheitemversion.get_instance()
                pythontype, javatype = TypeCaster.is_java_primitive(objtype)

                usejsonconversoin = False
                if javatype is None:
                        if isinstance(objtype(), collections.Collection):
                                javatype = JavaInstancesFactory.get_java_instance("JsonArray")
                        else:
                                javatype = JavaInstancesFactory.get_java_instance("JsonObject")
                        usejsonconversoin = True

                result = self.__cache.getIfNewer(javakey, javacacheitemversion, javatype)

                if result is not None:
                        if not usejsonconversoin:
                                result = pythontype(result)
                        else:
                                result = TypeCaster.deserialize(result, objtype, isjsonobject=True)
                return result

        def get_if_newer_cacheitem(self, key, cacheitemversion):
                """
                Gets an object from the cache only if a newer version of the object exists in cache.

                :param key: Unique key used to reference the desired object.
                :type key: str
                :param cacheitemversion: The CacheItemVersion of the object.
                :type cacheitemversion: CacheItemVersion
                :return: If a newer CacheItem exists in the cache, the CacheItem is returned. Otherwise, None is returned.
                :rtype: CacheItem or None
                """
                ValidateType.is_string(key, self.get_cacheitem)
                ValidateType.type_check(cacheitemversion, CacheItemVersion, self.get_if_newer_cacheitem)

                javacacheitemversion = cacheitemversion.get_instance()
                javakey = TypeCaster.to_java_primitive_type(key)

                result = self.__cache.getIfNewerCacheItem(javakey, javacacheitemversion)

                if result is not None:
                        cacheitem = CacheItem()
                        cacheitem.set_instance(result)
                        return cacheitem

                return result

        def delete(self, key, writethruoptions=None, lockhandle=None, version=None):
                """
                Deletes the item with the specified key from cache.

                :param key: Unique key of the item to be deleted.
                :type key: str
                :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WriteThru, WriteBehind or None.
                :type writethruoptions: WriteThruOptions
                :param lockhandle: If the item is locked, it can be removed only if the correct lockhandle is specified. lockhandle should be the same which was used initially to lock the item.
                :type lockhandle: LockHandle
                :param version: The version of the item to be removed. The item is removed from the cache only if this is still the most recent version in the cache.
                :type version: CacheItemVersion
                """

                ValidateType.is_string(key, self.delete)
                javakey = TypeCaster.to_java_primitive_type(key)

                if writethruoptions is not None:
                        ValidateType.type_check(writethruoptions, WriteThruOptions, self.delete)
                if lockhandle is not None and version is not None:
                        ValidateType.type_check(lockhandle, LockHandle, self.delete)
                        ValidateType.type_check(version, CacheItemVersion, self.delete)

                if version is not None:
                        javawritethruoptions = None
                        javalockhandle = None
                        
                        if writethruoptions is not None:
                                javawritethruoptions = writethruoptions.get_instance()

                        if lockhandle is not None:
                                javalockhandle = lockhandle.get_instance()

                        javaversion = version.get_instance()
                        self.__cache.delete(javakey, javalockhandle, javaversion, javawritethruoptions)
                        
                elif version is None and lockhandle is None:
                        javawritethruoptions = None
                        if writethruoptions is not None:
                                javawritethruoptions = writethruoptions.get_instance()
                        
                        self.__cache.delete(javakey, javawritethruoptions)

                else:
                        raise ValueError(ExceptionHandler.exceptionmessages.get("Cache.delete"))

        def delete_async(self, key, writethruoptions=None):
                """
                Deletes an item from the cache asynchronously with a cache key to reference its location.

                :param key:  Unique key of the item to be deleted.
                :type key: str
                :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WriteThru, WriteBehind or None.
                :type writethruoptions: WriteThruOptions
                :return: Task that performs a delete operation in the background
                :rtype: Task
                """
                return asyncio.create_task(self.__return_coroutine(self.delete, key, writethruoptions))

        def delete_bulk(self, keys, writethruoptions=None):
                """
                Deletes the specified items from the Cache. You can also specify the write option such that the items may be removed from both cache and data source.

                :param keys: Unique list of keys of the items to be deleted.
                :type keys: list
                :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WriteThru, WriteBehind or None.
                :type writethruoptions: WriteThruOptions
                """
                ValidateType.type_check(keys, list, self.delete_bulk)
                for key in keys:
                        ValidateType.is_string(key, self.delete_bulk)
                javakeys = TypeCaster.to_java_array_list(keys, True)
                if writethruoptions is not None:
                        ValidateType.type_check(writethruoptions, WriteThruOptions, self.delete_bulk)

                if writethruoptions is not None:
                        javawritethruoptions = writethruoptions.get_instance()
                        self.__cache.deleteBulk(javakeys, javawritethruoptions)
                else:
                        self.__cache.deleteBulk(javakeys)

        def remove(self, key, objtype, writethruoptions=None, lockhandle=None, version=None):
                """
                Removes and retrieves the item with the specified key from cache.

                :param key: Unique key of the item to be deleted.
                :type key: str
                :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either
                :type writethruoptions: WriteThruOptions
                :param objtype: Type of the item to be removed from cache
                :type objtype: type
                :param lockhandle: If the item is locked, it can be removed only if the correct lockhandle is specified. lockhandle should be the same which was used initially to lock the item.
                :type lockhandle: LockHandle
                :param version: The version of the item to be removed. The item is removed from the cache only if this is still the most recent version in the cache.
                :type version: CacheItemVersion
                :return: The removed item if the key exists otherwise None is returned.
                :rtype: object
                """

                ValidateType.is_string(key, self.remove)
                javakey = TypeCaster.to_java_primitive_type(key)

                if writethruoptions is not None:
                        ValidateType.type_check(writethruoptions, WriteThruOptions, self.remove)
                if lockhandle is not None and version is not None:
                        ValidateType.type_check(lockhandle, LockHandle, self.remove)
                        ValidateType.type_check(version, CacheItemVersion, self.remove)

                pythontype, javatype = TypeCaster.is_java_primitive(objtype)
                usejsonconversoin = False

                if javatype is None:
                        if isinstance(objtype(), collections.Collection):
                                javatype = JavaInstancesFactory.get_java_instance("JsonArray")
                        else:
                                javatype = JavaInstancesFactory.get_java_instance("JsonObject")
                        usejsonconversoin = True

                if version is not None:
                        javawritethruoptions = None
                        javalockhandle = None

                        if writethruoptions is not None:
                                javawritethruoptions = writethruoptions.get_instance()

                        if lockhandle is not None:
                                javalockhandle = lockhandle.get_instance()

                        javaversion = version.get_instance()
                        result = self.__cache.remove(javakey, javalockhandle, javaversion, javawritethruoptions, javatype)

                elif lockhandle is not None:
                        javalockhandle = lockhandle.get_instance()
                        javawritethruoptions = None
                        javaversion = None

                        if version is not None:
                                javaversion = version.get_instance()

                        if writethruoptions is not None:
                                javawritethruoptions = writethruoptions.get_instance()

                        result = self.__cache.remove(javakey, javalockhandle, javaversion, javawritethruoptions, javatype)
                elif lockhandle is None and version is None:
                        javawritethruoptions = None
                        
                        if writethruoptions is not None:
                                javawritethruoptions = writethruoptions.get_instance()

                        result = self.__cache.remove(javakey, javawritethruoptions, javatype)

                else:
                        raise ValueError(ExceptionHandler.exceptionmessages.get("Cache.remove"))

                if result is not None:
                        if not usejsonconversoin:
                                result = pythontype(result)
                        else:
                                result = TypeCaster.deserialize(result, objtype, isjsonobject=True)
                return result

        def remove_async(self, key, objtype, writethruoptions=None):
                """
                Removes an item from the cache asynchronously with a cache key to reference its location.

                :param key:  Unique key of the item to be deleted.
                :type key: str
                :param objtype: Type of the item to be removed from cache
                :type objtype: type
                :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WriteThru, WriteBehind or None.
                :type writethruoptions: WriteThruOptions
                :return: Task that performs a remove operation in the background. Once completed returns the removed cache item
                :rtype: Task
                """
                return asyncio.create_task(self.__return_coroutine(self.remove, key, objtype, writethruoptions))

        def remove_bulk(self, keys, objtype, writethruoptions=None):
                """
                Removes the specified items from the Cache and returns them to the application in the form of a Dictionary.

                :param keys: List of Unique keys of the item to be removed.
                :type keys: list
                :param objtype: Type of the item to be retrieved from cache
                :type objtype: type
                :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WRITE_THRU, WRITE_BEHIND or NONE.
                :type writethruoptions: WriteThruOptions
                :return: The removed items from cache in form of a Dictionary.
                :rtype: dict
                """
                ValidateType.type_check(keys, list, self.remove_bulk)
                for key in keys:
                        ValidateType.is_string(key, self.remove_bulk)

                ValidateType.type_check(objtype, type, self.remove_bulk)
                pythontype, javatype = TypeCaster.is_java_primitive(objtype)

                if javatype is None:
                        javatype = JavaInstancesFactory.get_java_instance("JsonObject")

                javakeys = TypeCaster.to_java_array_list(keys, True)
                if writethruoptions is not None:
                        ValidateType.type_check(writethruoptions, WriteThruOptions, self.remove_bulk)
                        javawritethruoptions = writethruoptions.get_instance()

                        result = self.__cache.removeBulk(javakeys, javawritethruoptions, javatype)
                else:
                        result = self.__cache.removeBulk(javakeys, javatype)

                return self.__bulk_result_to_dict(result, False, objtype)

        def contains(self, key):
                """
                Determines whether the cache contains a specific key.

                :param key: The key to locate in the cache.
                :type key: str
                :return: True if the Cache contains an element with the specified key; otherwise, False
                :rtype: bool
                """
                ValidateType.is_string(key, self.contains)
                javakey = TypeCaster.to_java_primitive_type(key)

                result = self.__cache.contains(javakey)

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

                return result

        def contains_bulk(self, keys):
                """
                Determines whether the cache contains specified keys.

                :param keys: List of keys.
                :type keys: list
                :return: Dictionary of Keys with flag to determine presence of each key in cache. <b>True</b> if the Cache contains an element with the specified key; otherwise, <b>False</b>.
                :rtype: dict
                """
                ValidateType.type_check(keys, list, self.contains_bulk)
                for key in keys:
                        ValidateType.is_string(key, self.contains_bulk)

                javakeys = TypeCaster.to_java_array_list(keys, isjavatype=True)
                result = self.__cache.containsBulk(javakeys)

                if result is not None:
                        return self.__bulk_result_to_dict(result)

        def clear(self):
                """
                Removes all elements from the Cache.
                """
                self.__cache.clear()

        def clear_client_cache(self):
                """
                Removes all elements from the client cache.
                """
                self.__cache.clearClientCache()

        def unlock(self, key, lockhandle=None):
                """
                Unlocks a locked cached item if the correct lockhandle is provided. Forcefully unlocks the item if no lockhandle is provided.

                :param key: Key of the cached item to be unlocked.
                :type key: str
                :param lockhandle: An instance of LockHandle that is generated when the lock is acquired.
                :type lockhandle: LockHandle
                """
                ValidateType.is_string(key, self.unlock)
                javakey = TypeCaster.to_java_primitive_type(key)

                if lockhandle is not None:
                        ValidateType.type_check(lockhandle, LockHandle, self.unlock)
                        javalockhandle = lockhandle.get_instance()

                        self.__cache.unlock(javakey, javalockhandle)

                else:
                        self.__cache.unlock(javakey)

        def lock(self, key, locktimeout, lockhandle):
                """
                Acquires a lock on an item in the cache.

                :param key: Key of cached item to be locked.
                :type key:str
                :param locktimeout: An instance of TimeSpan after which the lock is automatically released.
                :type locktimeout: TimeSpan
                :param lockhandle: An instance of LockHandle that will be filled in with the lock information if lock is acquired successfully.
                :type lockhandle: LockHandle
                :return: Whether or not lock was acquired successfully.
                :rtype: bool
                """
                ValidateType.is_string(key, self.lock)
                ValidateType.type_check(lockhandle, LockHandle, self.lock)
                ValidateType.type_check(locktimeout, TimeSpan, self.lock)

                javakey = TypeCaster.to_java_primitive_type(key)
                javalocktimeout = locktimeout.get_instance()
                javalockhandle = lockhandle.get_instance()

                result = self.__cache.lock(javakey, javalocktimeout, javalockhandle)

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

                return result

        def as_iterable(self):
                javaiterator = self.__cache.asIterator()
                iterator = Iterator(javaiterator, iskeysiterator=False, iscacheiterator=True)
                return iter(iterator)

        def close(self):
                """
                Closes this resource, relinquishing any underlying resources.
                """
                self.__cache.close()

        async def __return_coroutine(self, function, *args):
                if function == self.delete:
                        return function(args[0], args[1])
                else:
                        return function(args[0], args[1], args[2])
                # For the time being, we have only 2 or 3 possible arguments. This function has to be made generic if needed in future.

        @staticmethod
        def __bulk_result_to_dict(javabulkmap, isexception=False, objtype=None, iscacheitem=False):
                pythondict = {}

                for item in javabulkmap:
                        key = TypeCaster.to_python_primitive_type(item)
                        if isexception:
                                pythondict[key] = javabulkmap[item]
                        elif iscacheitem:
                                cacheitem = CacheItem()
                                cacheitem.set_instance(javabulkmap[item])
                                pythondict[key] = cacheitem
                        else:
                                pythontype = TypeCaster.to_python_primitive_type(javabulkmap[item])

                                if pythontype is not None:
                                        pythondict[key] = pythontype
                                else:
                                        pythondict[key] = TypeCaster.deserialize(javabulkmap[item], objtype, isjsonobject=True)

                return pythondict

클래스

class Cache (cache)

이 클래스에는 캐시에서 작업을 수행하는 데 사용되는 서비스 및 메서드가 포함되어 있습니다.

이 함수는 캐시의 인스턴스를 가져옵니다. 매개변수 캐시: 캐시의 인스턴스.

소스 코드 확장
class Cache:
        """
        This class contains the services and methods that are used to perform operations on the cache.
        """
        def __init__(self, cache):
                """
                This function gets an instance of the Cache
                :param cache: Instance of the Cache.
                """
                self.__cache = cache

        def __str__(self):
                result = self.__cache.toString()

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

        def get_instance(self):
                return self.__cache

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

        def get_count(self):
                """
                Gets the number of items stored in the cache

                :return: The number of items stored in the cache.
                :rtype: int
                """
                result = self.__cache.getCount()

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

                return result

        def get_notification_service(self):
                """
                Gets an instance of NotificationService

                :return: An instance of NotificationService
                :rtype: NotificationService
                """

                result = self.__cache.getNotificationService()

                if result is not None:
                        result = NotificationService(result)

                return result

        def get_messaging_service(self):
                """
                Gets an instance of MessagingService

                :return: An instance of MessagingService
                :rtype: MessagingService
                """
                result = self.__cache.getMessagingService()

                if result is not None:
                        result = MessagingService(result)

                return result

        def get_search_service(self):
                """
                Gets an instance of SearchService.

                :return: An instance of SearchService
                :rtype: SearchService
                """
                result = self.__cache.getSearchService()

                if result is not None:
                        result = SearchService(result)

                return result

        def get_data_structures_manager(self):
                """
                Gets an instance of DataStructureManager.

                :return: An instance of DataStructureManager
                :rtype: DataStructureManager
                """
                result = self.__cache.getDataStructuresManager()

                if result is not None:
                        result = DataStructureManager(result)

                return result

        def add(self, key, item, writethruoptions=None):
                """
                Adds an item or CacheItem into the Cache object with a cache key to reference its location. You can also
                specify WriteThruOptions

                :param key: Unique key to identify the cache item.
                :type key: str
                :param item: The item (object) or CacheItem to be stored in the cache.
                :type item: object or CacheItem
                :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either
                :type writethruoptions: WriteThruOptions
                :return: Represents the version of each cache item.
                :rtype: CacheItemVersion
                """

                ValidateType.is_key_value_valid(key, item, self.add)
                if writethruoptions is not None:
                        ValidateType.type_check(writethruoptions, WriteThruOptions, self.add)

                javatype = TypeCaster.is_python_primitive(item)
                javakey = TypeCaster.to_java_primitive_type(key)
                if javatype is not None:
                        if writethruoptions is None:
                                res = self.__cache.add(javakey, javatype)
                        else:
                                raise TypeError(ExceptionHandler.get_invalid_cache_add_exception_message(CacheItem))

                elif isinstance(item, CacheItem):
                        if writethruoptions is None:
                                res = self.__cache.add(javakey, item.get_instance())
                        else:
                                res = self.__cache.add(javakey, item.get_instance(), writethruoptions.get_instance())
                else:
                        if writethruoptions is None:
                                res = self.__cache.add(javakey, TypeCaster.serialize(item, isjsonobject=True))
                        else:
                                raise TypeError(ExceptionHandler.get_invalid_cache_add_exception_message(CacheItem))

                if res is not None:
                        return CacheItemVersion(int(res.getVersion()))

        def add_bulk(self, items, writethruoptions=None):
                """
                Adds a Dictionary of cache keys with CacheItem to the cache. You can also specify WriteThruOptions

                :param items: Dictionary of keys and CacheItem. Keys must be unique.
                :type items: dict
                :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WriteThru, WriteBehind or None.
                :type writethruoptions: WriteThruOptions
                :return: Dictionary of Keys along with Exception for items that were unable to store in cache.
                :rtype: dict
                """
                ValidateType.type_check(items, dict, self.add_bulk)
                for item in items:
                        ValidateType.is_string(item, self.add_bulk)
                        ValidateType.type_check(items[item], CacheItem, self.add_bulk)
                javaitems = TypeCaster.to_java_hash_map(items, False)

                if writethruoptions is not None:
                        ValidateType.type_check(writethruoptions, WriteThruOptions, self.add_bulk)
                        javawritethruoptions = writethruoptions.get_instance()

                        result = self.__cache.addBulk(javaitems, javawritethruoptions)
                else:
                        result = self.__cache.addBulk(javaitems)

                if result is not None:
                        return self.__bulk_result_to_dict(result, True)

        def add_async(self, key, item, writethruoptions=None):
                """
                Adds an item or a CacheItem to the cache asynchronously with a cache key to reference its location and with or without WriteThruOptions.

                :param key: Unique key to identify the cache item.
                :type key: str
                :param item: The item (object) or CacheItem to be stored in the cache.
                :type item: object
                :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either
                :type writethruoptions: WriteThruOptions
                :return: Task that performs an add operation in the background.
                :rtype: Task
                """
                return asyncio.create_task(self.__return_coroutine(self.add, key, item, writethruoptions))

        def insert(self, key, item, writethruoptions=None, lockhandle=None, releaselock=None):
                """
                Inserts an item or a CacheItem to the cache.

                :param key: Unique key to identify the cache item.
                :type key: str
                :param item: The value or the CacheItem that is to be inserted into the cache.
                :type item: object or CacheItem
                :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WriteThru, WriteBehind or None.
                :type writethruoptions: WriteThruOptions
                :param lockhandle: An instance of LockHandle that holds the lock information. If the item is locked, then it can only be updated if the correct lockHandle is specified.
                :type lockhandle: LockHandle
                :param releaselock: A flag to determine whether or not the lock should be released after operation is performed.
                :type releaselock: bool
                :return: Represents the version of each cache item.
                :rtype: CacheItemVersion
                """

                ValidateType.is_key_value_valid(key, item, self.insert)
                if writethruoptions is not None:
                        ValidateType.type_check(writethruoptions, WriteThruOptions, self.insert)

                if lockhandle is not None and releaselock is not None:
                        ValidateType.type_check(lockhandle, LockHandle, self.insert)
                        ValidateType.type_check(releaselock, bool, self.insert)

                javatype = TypeCaster.is_python_primitive(item)

                javakey = TypeCaster.to_java_primitive_type(key)

                if javatype is not None:
                        if writethruoptions is not None or lockhandle is not None or releaselock is not None:
                                raise TypeError(ExceptionHandler.get_invalid_cache_insert_exception_message(CacheItem))
                        res = self.__cache.insert(javakey, javatype)

                elif isinstance(item, CacheItem):
                        value = item.get_instance()

                        if lockhandle is not None and releaselock is not None:
                                javawritethruoptions = None
                                
                                if writethruoptions is not None:
                                        javawritethruoptions = writethruoptions.get_instance()
                                
                                javalockhandle = lockhandle.get_instance()
                                javareleaselock = TypeCaster.to_java_primitive_type(releaselock)
                                res = self.__cache.insert(javakey, value, javawritethruoptions, javalockhandle, javareleaselock)

                        elif lockhandle is not None or releaselock is not None:
                                raise ValueError(ExceptionHandler.exceptionmessages.get("Cache.insert"))

                        else:
                                javawritethruoptions = None
                                
                                if writethruoptions is not None:
                                        javawritethruoptions = writethruoptions.get_instance()
                                        
                                res = self.__cache.insert(javakey, value, javawritethruoptions)

                else:
                        if writethruoptions is not None or lockhandle is not None or releaselock is not None:
                                raise ValueError(ExceptionHandler.exceptionmessages.get("Cache.insert"))
                        value = TypeCaster.serialize(item, isjsonobject=True, verbose=True)
                        res = self.__cache.insert(javakey, value)

                if res is not None:
                        return CacheItemVersion(int(res.getVersion()))

        def insert_bulk(self, items, writethruoptions=None):
                """
                Inserts a Dictionary of cache keys with CacheItem to the cache with or without the WriteThruOptions.

                :param items: Dictionary of keys and CacheItem. Keys must be unique.
                :type items: dict
                :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WriteThru, WriteBehind or None.
                :type writethruoptions: WriteThruOptions
                :return: Dictionary of Keys along with Exception for items that were unable to store in cache.
                :rtype: dict
                """
                ValidateType.type_check(items, dict, self.insert_bulk)
                for item in items:
                        ValidateType.is_string(item, self.insert_bulk)
                        ValidateType.type_check(items[item], CacheItem, self.insert_bulk)
                javaitems = TypeCaster.to_java_hash_map(items, False)

                if writethruoptions is not None:
                        ValidateType.type_check(writethruoptions, WriteThruOptions, self.insert_bulk)
                        javawritethruoptions = writethruoptions.get_instance()

                        result = self.__cache.insertBulk(javaitems, javawritethruoptions)
                else:
                        result = self.__cache.insertBulk(javaitems)

                if result is not None:
                        return self.__bulk_result_to_dict(result, True)

        def insert_async(self, key, item, writethruoptions=None):
                """
                Inserts an item or a CacheItem to the cache asynchronously with a cache key to reference its location and with or without WriteThruOptions.

                :param key: Unique key to identify the cache item.
                :type key: str
                :param item: The item (object) or CacheItem to be stored in the cache.
                :type item: object
                :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WriteThru, WriteBehind or None.
                :type writethruoptions: WriteThruOptions
                :return: Task that performs an insert operation in the background.
                :rtype: Task
                """
                return asyncio.create_task(self.__return_coroutine(self.insert, key, item, writethruoptions))

        def update_attributes(self, key, attributes):
                """
                Update CacheItemAttributes of an existing item in cache.

                :param key: Unique key to identify the cache item.
                :type key: str
                :param attributes: An instance of CacheItemAttributes to update item in the cache.
                :type attributes: CacheItemAttributes
                :return: Flag that determines status of the update operation. True if attributes of the item in cache was updated successfully otherwise False.
                :rtype: bool
                """
                ValidateType.is_string(key, self.update_attributes)
                ValidateType.type_check(attributes, CacheItemAttributes, self.update_attributes)

                javakey = TypeCaster.to_java_primitive_type(key)
                javaattributes = attributes.get_instance()

                result = self.__cache.updateAttributes(javakey, javaattributes)

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

                return result

        def get(self, key, objtype, readthruoptions=None, cacheitemversion=None, acquirelock=None, locktimeout=None, lockhandle=None):
                """
                Retrieves the specified item from the Cache object.

                :param key: Unique key to identify the cache item.
                :type key: str
                :param objtype: Type of the item to be retrieved from cache
                :type objtype: type
                :param readthruoptions: ReadThruOptions to read from data source. These can be either ReadThru, ReadThruForced or None.
                :type readthruoptions: ReadThruOptions
                :param acquirelock: A flag to determine whether to acquire a lock or not.
                :type acquirelock: bool
                :param locktimeout: The TimeSpan after which the lock is automatically released.
                :type locktimeout: TimeSpan
                :param lockhandle: An instance of LockHandle to hold the lock information.
                :type lockhandle: LockHandle
                :param cacheitemversion: The version of the object. If None is passed for CacheItemVersion, then the version of the object from the cache is returned. If non-None CacheItemVersion is passed, then object is returned from the cache only if that is the current version of the object in the cache.
                :type cacheitemversion: CacheItemVersion
                :return: The retrieved cache item, or a None reference if the key is not found.
                :rtype: object
                """

                ValidateType.is_string(key, self.get)
                javakey = TypeCaster.to_java_primitive_type(key)

                ValidateType.type_check(objtype, type, self.get)

                if readthruoptions is not None:
                        ValidateType.type_check(readthruoptions, ReadThruOptions, self.get)

                if locktimeout is not None and lockhandle is not None and acquirelock is not None:
                        ValidateType.type_check(lockhandle, LockHandle, self.get)
                        ValidateType.type_check(locktimeout, TimeSpan, self.get)
                        ValidateType.type_check(acquirelock, bool, self.get)

                if cacheitemversion is not None:
                        ValidateType.type_check(cacheitemversion, CacheItemVersion, self.get)

                pythontype, javatype = TypeCaster.is_java_primitive(objtype)

                usejsonconversoin = False
                if javatype is None:
                        if isinstance(objtype(), collections.Collection):
                                javatype = JavaInstancesFactory.get_java_instance("JsonArray")
                        else:
                                javatype = JavaInstancesFactory.get_java_instance("JsonObject")
                        usejsonconversoin = True
                
                if cacheitemversion is not None:
                        javacacheitemversion = cacheitemversion.get_instance()
                        javareadthruoptions = None
                        
                        if readthruoptions is not None:
                                javareadthruoptions = readthruoptions.get_instance()

                        result = self.__cache.get(javakey, javacacheitemversion, javareadthruoptions, javatype)

                elif locktimeout is not None and lockhandle is not None and acquirelock is not None:
                        javalockhandle = lockhandle.get_instance()
                        javalocktimeout = locktimeout.get_instance()
                        javaacquirelock = TypeCaster.to_java_primitive_type(acquirelock)
                        result = self.__cache.get(javakey, javaacquirelock, javalocktimeout, javalockhandle, javatype)

                elif locktimeout is None and lockhandle is None and acquirelock is None and cacheitemversion is None:
                        javareadthruoptions = None
                        
                        if readthruoptions is not None:
                                javareadthruoptions = readthruoptions.get_instance()

                        result = self.__cache.get(javakey, javareadthruoptions, javatype)

                else:
                        raise ValueError(ExceptionHandler.exceptionmessages.get("Cache.get"))

                if result is not None:
                        if not usejsonconversoin:
                                result = pythontype(result)
                        else:
                                result = TypeCaster.deserialize(result, objtype, isjsonobject=True)
                return result

        def get_bulk(self, keys, objtype, readthruoptions=None):
                """
                Retrieves the objects from cache for the given keys as key-value pairs in form of a Dictionary.

                :param keys: The list keys against which items are to be fetched from cache.
                :type keys: list
                :param objtype: Type of the item to be retrieved from cache
                :type objtype: type
                :param readthruoptions: ReadThruOptions to read from data source. These can be either ReadThru, ReadThruForced or None.
                :type readthruoptions: ReadThruOptions
                :return: The retrieved cache items as Dictionary of key-value pairs.
                :rtype: dict
                """
                ValidateType.type_check(objtype, type, self.get_bulk)
                ValidateType.type_check(keys, list, self.get_bulk)
                for key in keys:
                        ValidateType.is_string(key, self.get_bulk)
                javakeys = TypeCaster.to_java_array_list(keys, True)

                pythontype, javatype = TypeCaster.is_java_primitive(objtype)

                if javatype is None:
                        javatype = JavaInstancesFactory.get_java_instance("JsonObject")

                javareadthruoptions = None

                if readthruoptions is not None:
                        ValidateType.type_check(readthruoptions, ReadThruOptions, self.get_bulk)
                        javareadthruoptions = readthruoptions.get_instance()

                result = self.__cache.getBulk(javakeys, javareadthruoptions, javatype)

                if result is not None:
                        return self.__bulk_result_to_dict(result, False, objtype)

        def get_cacheitem(self, key, readthruoptions=None, cacheitemversion=None, acquirelock=None, locktimeout=None, lockhandle=None):
                """
                Retrieves the specified CacheItem from the Cache object.

                :param key: Unique key to identify the cache item.
                :type key: str
                :param readthruoptions: ReadThruOptions to read from data source. These can be either ReadThru, ReadThruForced or None.
                :type readthruoptions: ReadThruOptions
                :param acquirelock: A flag to determine whether to acquire a lock or not.
                :type acquirelock: bool
                :param locktimeout: The TimeSpan after which the lock is automatically released.
                :type locktimeout: TimeSpan
                :param lockhandle: An instance of LockHandle to hold the lock information.
                :type lockhandle: LockHandle
                :param cacheitemversion: The version of the object. If None is passed for CacheItemVersion, then the version of
                        the object from the cache is returned. If non-None CacheItemVersion is passed, then object is returned from
                        the cache only if that is the current version of the object in the cache.
                :type cacheitemversion: CacheItemVersion
                :return: The retrieved CacheItem, or a None reference if the key is not found.
                :rtype: CacheItem
                """
                ValidateType.is_string(key, self.get_cacheitem)
                javakey = TypeCaster.to_java_primitive_type(key)
                if readthruoptions is not None:
                        ValidateType.type_check(readthruoptions, ReadThruOptions, self.get_cacheitem)

                if cacheitemversion is not None:
                        ValidateType.type_check(cacheitemversion, CacheItemVersion, self.get_cacheitem)

                if acquirelock is not None and lockhandle is not None and locktimeout is not None:
                        ValidateType.type_check(acquirelock, bool, self.get_cacheitem)
                        ValidateType.type_check(lockhandle, LockHandle, self.get_cacheitem)
                        ValidateType.type_check(locktimeout, TimeSpan, self.get_cacheitem)

                if cacheitemversion is not None:
                        javareadthruoptions = None
                        
                        if readthruoptions is not None:
                                javareadthruoptions = readthruoptions.get_instance()

                        javacacheitemversion = cacheitemversion.get_instance()
                        result = self.__cache.getCacheItem(javakey, javacacheitemversion, javareadthruoptions)

                elif acquirelock is not None and lockhandle is not None and locktimeout is not None:
                        javaacquirelock = TypeCaster.to_java_primitive_type(acquirelock)
                        javalockhandle = lockhandle.get_instance()
                        javalocktimeout = locktimeout.get_instance()
                        result = self.__cache.getCacheItem(javakey, javaacquirelock, javalocktimeout, javalockhandle)

                elif cacheitemversion is None and acquirelock is None and lockhandle is None and locktimeout is None:
                        javareadthruoptions = None
                        
                        if readthruoptions is not None:
                                javareadthruoptions = readthruoptions.get_instance()

                        result = self.__cache.getCacheItem(javakey, javareadthruoptions)

                else:
                        raise ValueError(ExceptionHandler.exceptionmessages.get("Cache.get_cacheitem"))

                if result is not None:
                        cacheitem = CacheItem()
                        cacheitem.set_instance(result)
                        return cacheitem

                return result

        def get_cacheitem_bulk(self, keys, readthruoptions=None):
                """
                Retrieves the CacheItems from cache for the given keys as key-value pairs in form of a Dictionary.

                :param keys: The keys against which CacheItems are to be fetched from cache.
                :type keys: list
                :param readthruoptions: ReadThruOptions to read from data source. These can be either ReadThru, ReadThruForced or None.
                :type readthruoptions: ReadThruOptions
                :return: The retrieved CacheItems as Dictionary of key-value pairs.
                :rtype: dict
                """
                ValidateType.type_check(keys, list, self.get_cacheitem_bulk)
                for key in keys:
                        ValidateType.is_string(key, self.get_cacheitem_bulk)
                javakeys = TypeCaster.to_java_array_list(keys, True)

                if readthruoptions is not None:
                        ValidateType.type_check(readthruoptions, ReadThruOptions, self.get_cacheitem_bulk)
                        javareadthruoptions = readthruoptions.get_instance()
                        result = self.__cache.getCacheItemBulk(javakeys, javareadthruoptions)

                else:
                        result = self.__cache.getCacheItemBulk(javakeys)

                if result is not None:
                        return self.__bulk_result_to_dict(result, iscacheitem=True)

        def get_if_newer(self, key, cacheitemversion, objtype):
                """
                Gets an object from the cache only if a newer version of the object exists in cache.

                :param key: Unique key used to reference the desired object.
                :type key: str
                :param cacheitemversion: The CacheItemVersion of the object.
                :type cacheitemversion: CacheItemVersion
                :param objtype: Type of the item to be removed from cache
                :type objtype: type
                :return: If a newer object exists in the cache, the object is returned. Otherwise, None is returned.
                :rtype: object or None
                """
                ValidateType.is_string(key, self.get_if_newer)
                ValidateType.type_check(cacheitemversion, CacheItemVersion, self.get_if_newer)
                ValidateType.type_check(objtype, type, self.get_if_newer)

                javakey = TypeCaster.to_java_primitive_type(key)
                javacacheitemversion = cacheitemversion.get_instance()
                pythontype, javatype = TypeCaster.is_java_primitive(objtype)

                usejsonconversoin = False
                if javatype is None:
                        if isinstance(objtype(), collections.Collection):
                                javatype = JavaInstancesFactory.get_java_instance("JsonArray")
                        else:
                                javatype = JavaInstancesFactory.get_java_instance("JsonObject")
                        usejsonconversoin = True

                result = self.__cache.getIfNewer(javakey, javacacheitemversion, javatype)

                if result is not None:
                        if not usejsonconversoin:
                                result = pythontype(result)
                        else:
                                result = TypeCaster.deserialize(result, objtype, isjsonobject=True)
                return result

        def get_if_newer_cacheitem(self, key, cacheitemversion):
                """
                Gets an object from the cache only if a newer version of the object exists in cache.

                :param key: Unique key used to reference the desired object.
                :type key: str
                :param cacheitemversion: The CacheItemVersion of the object.
                :type cacheitemversion: CacheItemVersion
                :return: If a newer CacheItem exists in the cache, the CacheItem is returned. Otherwise, None is returned.
                :rtype: CacheItem or None
                """
                ValidateType.is_string(key, self.get_cacheitem)
                ValidateType.type_check(cacheitemversion, CacheItemVersion, self.get_if_newer_cacheitem)

                javacacheitemversion = cacheitemversion.get_instance()
                javakey = TypeCaster.to_java_primitive_type(key)

                result = self.__cache.getIfNewerCacheItem(javakey, javacacheitemversion)

                if result is not None:
                        cacheitem = CacheItem()
                        cacheitem.set_instance(result)
                        return cacheitem

                return result

        def delete(self, key, writethruoptions=None, lockhandle=None, version=None):
                """
                Deletes the item with the specified key from cache.

                :param key: Unique key of the item to be deleted.
                :type key: str
                :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WriteThru, WriteBehind or None.
                :type writethruoptions: WriteThruOptions
                :param lockhandle: If the item is locked, it can be removed only if the correct lockhandle is specified. lockhandle should be the same which was used initially to lock the item.
                :type lockhandle: LockHandle
                :param version: The version of the item to be removed. The item is removed from the cache only if this is still the most recent version in the cache.
                :type version: CacheItemVersion
                """

                ValidateType.is_string(key, self.delete)
                javakey = TypeCaster.to_java_primitive_type(key)

                if writethruoptions is not None:
                        ValidateType.type_check(writethruoptions, WriteThruOptions, self.delete)
                if lockhandle is not None and version is not None:
                        ValidateType.type_check(lockhandle, LockHandle, self.delete)
                        ValidateType.type_check(version, CacheItemVersion, self.delete)

                if version is not None:
                        javawritethruoptions = None
                        javalockhandle = None
                        
                        if writethruoptions is not None:
                                javawritethruoptions = writethruoptions.get_instance()

                        if lockhandle is not None:
                                javalockhandle = lockhandle.get_instance()

                        javaversion = version.get_instance()
                        self.__cache.delete(javakey, javalockhandle, javaversion, javawritethruoptions)
                        
                elif version is None and lockhandle is None:
                        javawritethruoptions = None
                        if writethruoptions is not None:
                                javawritethruoptions = writethruoptions.get_instance()
                        
                        self.__cache.delete(javakey, javawritethruoptions)

                else:
                        raise ValueError(ExceptionHandler.exceptionmessages.get("Cache.delete"))

        def delete_async(self, key, writethruoptions=None):
                """
                Deletes an item from the cache asynchronously with a cache key to reference its location.

                :param key:  Unique key of the item to be deleted.
                :type key: str
                :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WriteThru, WriteBehind or None.
                :type writethruoptions: WriteThruOptions
                :return: Task that performs a delete operation in the background
                :rtype: Task
                """
                return asyncio.create_task(self.__return_coroutine(self.delete, key, writethruoptions))

        def delete_bulk(self, keys, writethruoptions=None):
                """
                Deletes the specified items from the Cache. You can also specify the write option such that the items may be removed from both cache and data source.

                :param keys: Unique list of keys of the items to be deleted.
                :type keys: list
                :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WriteThru, WriteBehind or None.
                :type writethruoptions: WriteThruOptions
                """
                ValidateType.type_check(keys, list, self.delete_bulk)
                for key in keys:
                        ValidateType.is_string(key, self.delete_bulk)
                javakeys = TypeCaster.to_java_array_list(keys, True)
                if writethruoptions is not None:
                        ValidateType.type_check(writethruoptions, WriteThruOptions, self.delete_bulk)

                if writethruoptions is not None:
                        javawritethruoptions = writethruoptions.get_instance()
                        self.__cache.deleteBulk(javakeys, javawritethruoptions)
                else:
                        self.__cache.deleteBulk(javakeys)

        def remove(self, key, objtype, writethruoptions=None, lockhandle=None, version=None):
                """
                Removes and retrieves the item with the specified key from cache.

                :param key: Unique key of the item to be deleted.
                :type key: str
                :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either
                :type writethruoptions: WriteThruOptions
                :param objtype: Type of the item to be removed from cache
                :type objtype: type
                :param lockhandle: If the item is locked, it can be removed only if the correct lockhandle is specified. lockhandle should be the same which was used initially to lock the item.
                :type lockhandle: LockHandle
                :param version: The version of the item to be removed. The item is removed from the cache only if this is still the most recent version in the cache.
                :type version: CacheItemVersion
                :return: The removed item if the key exists otherwise None is returned.
                :rtype: object
                """

                ValidateType.is_string(key, self.remove)
                javakey = TypeCaster.to_java_primitive_type(key)

                if writethruoptions is not None:
                        ValidateType.type_check(writethruoptions, WriteThruOptions, self.remove)
                if lockhandle is not None and version is not None:
                        ValidateType.type_check(lockhandle, LockHandle, self.remove)
                        ValidateType.type_check(version, CacheItemVersion, self.remove)

                pythontype, javatype = TypeCaster.is_java_primitive(objtype)
                usejsonconversoin = False

                if javatype is None:
                        if isinstance(objtype(), collections.Collection):
                                javatype = JavaInstancesFactory.get_java_instance("JsonArray")
                        else:
                                javatype = JavaInstancesFactory.get_java_instance("JsonObject")
                        usejsonconversoin = True

                if version is not None:
                        javawritethruoptions = None
                        javalockhandle = None

                        if writethruoptions is not None:
                                javawritethruoptions = writethruoptions.get_instance()

                        if lockhandle is not None:
                                javalockhandle = lockhandle.get_instance()

                        javaversion = version.get_instance()
                        result = self.__cache.remove(javakey, javalockhandle, javaversion, javawritethruoptions, javatype)

                elif lockhandle is not None:
                        javalockhandle = lockhandle.get_instance()
                        javawritethruoptions = None
                        javaversion = None

                        if version is not None:
                                javaversion = version.get_instance()

                        if writethruoptions is not None:
                                javawritethruoptions = writethruoptions.get_instance()

                        result = self.__cache.remove(javakey, javalockhandle, javaversion, javawritethruoptions, javatype)
                elif lockhandle is None and version is None:
                        javawritethruoptions = None
                        
                        if writethruoptions is not None:
                                javawritethruoptions = writethruoptions.get_instance()

                        result = self.__cache.remove(javakey, javawritethruoptions, javatype)

                else:
                        raise ValueError(ExceptionHandler.exceptionmessages.get("Cache.remove"))

                if result is not None:
                        if not usejsonconversoin:
                                result = pythontype(result)
                        else:
                                result = TypeCaster.deserialize(result, objtype, isjsonobject=True)
                return result

        def remove_async(self, key, objtype, writethruoptions=None):
                """
                Removes an item from the cache asynchronously with a cache key to reference its location.

                :param key:  Unique key of the item to be deleted.
                :type key: str
                :param objtype: Type of the item to be removed from cache
                :type objtype: type
                :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WriteThru, WriteBehind or None.
                :type writethruoptions: WriteThruOptions
                :return: Task that performs a remove operation in the background. Once completed returns the removed cache item
                :rtype: Task
                """
                return asyncio.create_task(self.__return_coroutine(self.remove, key, objtype, writethruoptions))

        def remove_bulk(self, keys, objtype, writethruoptions=None):
                """
                Removes the specified items from the Cache and returns them to the application in the form of a Dictionary.

                :param keys: List of Unique keys of the item to be removed.
                :type keys: list
                :param objtype: Type of the item to be retrieved from cache
                :type objtype: type
                :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WRITE_THRU, WRITE_BEHIND or NONE.
                :type writethruoptions: WriteThruOptions
                :return: The removed items from cache in form of a Dictionary.
                :rtype: dict
                """
                ValidateType.type_check(keys, list, self.remove_bulk)
                for key in keys:
                        ValidateType.is_string(key, self.remove_bulk)

                ValidateType.type_check(objtype, type, self.remove_bulk)
                pythontype, javatype = TypeCaster.is_java_primitive(objtype)

                if javatype is None:
                        javatype = JavaInstancesFactory.get_java_instance("JsonObject")

                javakeys = TypeCaster.to_java_array_list(keys, True)
                if writethruoptions is not None:
                        ValidateType.type_check(writethruoptions, WriteThruOptions, self.remove_bulk)
                        javawritethruoptions = writethruoptions.get_instance()

                        result = self.__cache.removeBulk(javakeys, javawritethruoptions, javatype)
                else:
                        result = self.__cache.removeBulk(javakeys, javatype)

                return self.__bulk_result_to_dict(result, False, objtype)

        def contains(self, key):
                """
                Determines whether the cache contains a specific key.

                :param key: The key to locate in the cache.
                :type key: str
                :return: True if the Cache contains an element with the specified key; otherwise, False
                :rtype: bool
                """
                ValidateType.is_string(key, self.contains)
                javakey = TypeCaster.to_java_primitive_type(key)

                result = self.__cache.contains(javakey)

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

                return result

        def contains_bulk(self, keys):
                """
                Determines whether the cache contains specified keys.

                :param keys: List of keys.
                :type keys: list
                :return: Dictionary of Keys with flag to determine presence of each key in cache. <b>True</b> if the Cache contains an element with the specified key; otherwise, <b>False</b>.
                :rtype: dict
                """
                ValidateType.type_check(keys, list, self.contains_bulk)
                for key in keys:
                        ValidateType.is_string(key, self.contains_bulk)

                javakeys = TypeCaster.to_java_array_list(keys, isjavatype=True)
                result = self.__cache.containsBulk(javakeys)

                if result is not None:
                        return self.__bulk_result_to_dict(result)

        def clear(self):
                """
                Removes all elements from the Cache.
                """
                self.__cache.clear()

        def clear_client_cache(self):
                """
                Removes all elements from the client cache.
                """
                self.__cache.clearClientCache()

        def unlock(self, key, lockhandle=None):
                """
                Unlocks a locked cached item if the correct lockhandle is provided. Forcefully unlocks the item if no lockhandle is provided.

                :param key: Key of the cached item to be unlocked.
                :type key: str
                :param lockhandle: An instance of LockHandle that is generated when the lock is acquired.
                :type lockhandle: LockHandle
                """
                ValidateType.is_string(key, self.unlock)
                javakey = TypeCaster.to_java_primitive_type(key)

                if lockhandle is not None:
                        ValidateType.type_check(lockhandle, LockHandle, self.unlock)
                        javalockhandle = lockhandle.get_instance()

                        self.__cache.unlock(javakey, javalockhandle)

                else:
                        self.__cache.unlock(javakey)

        def lock(self, key, locktimeout, lockhandle):
                """
                Acquires a lock on an item in the cache.

                :param key: Key of cached item to be locked.
                :type key:str
                :param locktimeout: An instance of TimeSpan after which the lock is automatically released.
                :type locktimeout: TimeSpan
                :param lockhandle: An instance of LockHandle that will be filled in with the lock information if lock is acquired successfully.
                :type lockhandle: LockHandle
                :return: Whether or not lock was acquired successfully.
                :rtype: bool
                """
                ValidateType.is_string(key, self.lock)
                ValidateType.type_check(lockhandle, LockHandle, self.lock)
                ValidateType.type_check(locktimeout, TimeSpan, self.lock)

                javakey = TypeCaster.to_java_primitive_type(key)
                javalocktimeout = locktimeout.get_instance()
                javalockhandle = lockhandle.get_instance()

                result = self.__cache.lock(javakey, javalocktimeout, javalockhandle)

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

                return result

        def as_iterable(self):
                javaiterator = self.__cache.asIterator()
                iterator = Iterator(javaiterator, iskeysiterator=False, iscacheiterator=True)
                return iter(iterator)

        def close(self):
                """
                Closes this resource, relinquishing any underlying resources.
                """
                self.__cache.close()

        async def __return_coroutine(self, function, *args):
                if function == self.delete:
                        return function(args[0], args[1])
                else:
                        return function(args[0], args[1], args[2])
                # For the time being, we have only 2 or 3 possible arguments. This function has to be made generic if needed in future.

        @staticmethod
        def __bulk_result_to_dict(javabulkmap, isexception=False, objtype=None, iscacheitem=False):
                pythondict = {}

                for item in javabulkmap:
                        key = TypeCaster.to_python_primitive_type(item)
                        if isexception:
                                pythondict[key] = javabulkmap[item]
                        elif iscacheitem:
                                cacheitem = CacheItem()
                                cacheitem.set_instance(javabulkmap[item])
                                pythondict[key] = cacheitem
                        else:
                                pythontype = TypeCaster.to_python_primitive_type(javabulkmap[item])

                                if pythontype is not None:
                                        pythondict[key] = pythontype
                                else:
                                        pythondict[key] = TypeCaster.deserialize(javabulkmap[item], objtype, isjsonobject=True)

                return pythondict

행동 양식

def add(self, key, item, writethruoptions=None)

해당 위치를 참조하기 위해 캐시 키를 사용하여 항목 또는 CacheItem을 Cache 개체에 추가합니다. WriteThruOptions를 지정할 수도 있습니다.

:param key: 캐시 항목을 식별하는 고유 키입니다. :type key: str :param item: 캐시에 저장될 항목(객체) 또는 CacheItem. :type item: object 또는 CacheItem :param writethruoptions: 데이터 소스 업데이트에 관한 WriteThruOptions. 다음 중 하나일 수 있습니다. :type writethruoptions: WriteThruOptions :return: 각 캐시 항목의 버전을 나타냅니다. :rtype: CacheItemVersion

소스 코드 확장
def add(self, key, item, writethruoptions=None):
        """
        Adds an item or CacheItem into the Cache object with a cache key to reference its location. You can also
        specify WriteThruOptions

        :param key: Unique key to identify the cache item.
        :type key: str
        :param item: The item (object) or CacheItem to be stored in the cache.
        :type item: object or CacheItem
        :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either
        :type writethruoptions: WriteThruOptions
        :return: Represents the version of each cache item.
        :rtype: CacheItemVersion
        """

        ValidateType.is_key_value_valid(key, item, self.add)
        if writethruoptions is not None:
                ValidateType.type_check(writethruoptions, WriteThruOptions, self.add)

        javatype = TypeCaster.is_python_primitive(item)
        javakey = TypeCaster.to_java_primitive_type(key)
        if javatype is not None:
                if writethruoptions is None:
                        res = self.__cache.add(javakey, javatype)
                else:
                        raise TypeError(ExceptionHandler.get_invalid_cache_add_exception_message(CacheItem))

        elif isinstance(item, CacheItem):
                if writethruoptions is None:
                        res = self.__cache.add(javakey, item.get_instance())
                else:
                        res = self.__cache.add(javakey, item.get_instance(), writethruoptions.get_instance())
        else:
                if writethruoptions is None:
                        res = self.__cache.add(javakey, TypeCaster.serialize(item, isjsonobject=True))
                else:
                        raise TypeError(ExceptionHandler.get_invalid_cache_add_exception_message(CacheItem))

        if res is not None:
                return CacheItemVersion(int(res.getVersion()))
def add_async(self, key, item, writethruoptions=None)

WriteThruOptions를 사용하거나 사용하지 않고 해당 위치를 참조하는 캐시 키를 사용하여 항목 또는 CacheItem을 캐시에 비동기적으로 추가합니다.

:param key: 캐시 항목을 식별하는 고유 키입니다. :type key: str :param item: 캐시에 저장될 항목(객체) 또는 CacheItem. :type item: object :param writethruoptions: 데이터 소스 업데이트에 관한 WriteThruOptions. 이것은 :type writethruoptions: WriteThruOptions :return: 백그라운드에서 추가 작업을 수행하는 작업입니다. :rtype: 작업

소스 코드 확장
def add_async(self, key, item, writethruoptions=None):
        """
        Adds an item or a CacheItem to the cache asynchronously with a cache key to reference its location and with or without WriteThruOptions.

        :param key: Unique key to identify the cache item.
        :type key: str
        :param item: The item (object) or CacheItem to be stored in the cache.
        :type item: object
        :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either
        :type writethruoptions: WriteThruOptions
        :return: Task that performs an add operation in the background.
        :rtype: Task
        """
        return asyncio.create_task(self.__return_coroutine(self.add, key, item, writethruoptions))
def add_bulk(self, items, writethruoptions=None)

CacheItem이 있는 캐시 키 사전을 캐시에 추가합니다. WriteThruOptions를 지정할 수도 있습니다.

:param items: 키와 CacheItem의 사전. 키는 고유해야 합니다. :type items: dict :param writethruoptions: 데이터 소스 업데이트에 관한 WriteThruOptions. WriteThru, WriteBehind 또는 None일 수 있습니다. :type writethruoptions: WriteThruOptions :return: 캐시에 저장할 수 없는 항목에 대한 예외와 함께 키 사전. :rtype: 사전

소스 코드 확장
def add_bulk(self, items, writethruoptions=None):
        """
        Adds a Dictionary of cache keys with CacheItem to the cache. You can also specify WriteThruOptions

        :param items: Dictionary of keys and CacheItem. Keys must be unique.
        :type items: dict
        :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WriteThru, WriteBehind or None.
        :type writethruoptions: WriteThruOptions
        :return: Dictionary of Keys along with Exception for items that were unable to store in cache.
        :rtype: dict
        """
        ValidateType.type_check(items, dict, self.add_bulk)
        for item in items:
                ValidateType.is_string(item, self.add_bulk)
                ValidateType.type_check(items[item], CacheItem, self.add_bulk)
        javaitems = TypeCaster.to_java_hash_map(items, False)

        if writethruoptions is not None:
                ValidateType.type_check(writethruoptions, WriteThruOptions, self.add_bulk)
                javawritethruoptions = writethruoptions.get_instance()

                result = self.__cache.addBulk(javaitems, javawritethruoptions)
        else:
                result = self.__cache.addBulk(javaitems)

        if result is not None:
                return self.__bulk_result_to_dict(result, True)
def as_iterable(self)
소스 코드 확장
def as_iterable(self):
        javaiterator = self.__cache.asIterator()
        iterator = Iterator(javaiterator, iskeysiterator=False, iscacheiterator=True)
        return iter(iterator)
def clear(self)

캐시에서 모든 요소를 ​​제거합니다.

소스 코드 확장
def clear(self):
        """
        Removes all elements from the Cache.
        """
        self.__cache.clear()
def clear_client_cache(self)

클라이언트 캐시에서 모든 요소를 ​​제거합니다.

소스 코드 확장
def clear_client_cache(self):
        """
        Removes all elements from the client cache.
        """
        self.__cache.clearClientCache()
def close(self)

기본 리소스를 포기하고 이 리소스를 닫습니다.

소스 코드 확장
def close(self):
        """
        Closes this resource, relinquishing any underlying resources.
        """
        self.__cache.close()
def contains(self, key)

캐시에 특정 키가 포함되어 있는지 확인합니다.

:param key: 캐시에서 찾을 키입니다. :type key: str :return: Cache에 지정된 키가 있는 요소가 포함되어 있으면 True이고, 그렇지 않으면 True입니다. 그렇지 않으면 False :rtype: bool

소스 코드 확장
def contains(self, key):
        """
        Determines whether the cache contains a specific key.

        :param key: The key to locate in the cache.
        :type key: str
        :return: True if the Cache contains an element with the specified key; otherwise, False
        :rtype: bool
        """
        ValidateType.is_string(key, self.contains)
        javakey = TypeCaster.to_java_primitive_type(key)

        result = self.__cache.contains(javakey)

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

        return result
def contains_bulk(self, keys)

캐시에 지정된 키가 포함되어 있는지 확인합니다.

:param keys: 키 목록. :type keys: list :return: 캐시에 있는 각 키의 존재 여부를 판별하기 위한 플래그가 있는 키 사전. 참된 캐시에 지정된 키가 있는 요소가 포함된 경우; 그렇지 않으면, 거짓. :rtype: 사전

소스 코드 확장
def contains_bulk(self, keys):
        """
        Determines whether the cache contains specified keys.

        :param keys: List of keys.
        :type keys: list
        :return: Dictionary of Keys with flag to determine presence of each key in cache. <b>True</b> if the Cache contains an element with the specified key; otherwise, <b>False</b>.
        :rtype: dict
        """
        ValidateType.type_check(keys, list, self.contains_bulk)
        for key in keys:
                ValidateType.is_string(key, self.contains_bulk)

        javakeys = TypeCaster.to_java_array_list(keys, isjavatype=True)
        result = self.__cache.containsBulk(javakeys)

        if result is not None:
                return self.__bulk_result_to_dict(result)
def delete(self, key, writethruoptions=None, lockhandle=None, version=None)

캐시에서 지정된 키를 가진 항목을 삭제합니다.

:param key: 삭제할 항목의 고유 키입니다. :type key: str :param writethruoptions: 데이터 소스 업데이트에 관한 WriteThruOptions. WriteThru, WriteBehind 또는 None일 수 있습니다. :type writethruoptions: WriteThruOptions :param lockhandle: 항목이 잠겨 있으면 올바른 잠금 핸들이 지정된 경우에만 항목을 제거할 수 있습니다. lockhandle은 처음에 항목을 잠그는 데 사용된 것과 동일해야 합니다. :type lockhandle: LockHandle :param version: 제거할 항목의 버전. 캐시에서 여전히 최신 버전인 경우에만 항목이 캐시에서 제거됩니다. :유형 버전: CacheItemVersion

소스 코드 확장
def delete(self, key, writethruoptions=None, lockhandle=None, version=None):
        """
        Deletes the item with the specified key from cache.

        :param key: Unique key of the item to be deleted.
        :type key: str
        :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WriteThru, WriteBehind or None.
        :type writethruoptions: WriteThruOptions
        :param lockhandle: If the item is locked, it can be removed only if the correct lockhandle is specified. lockhandle should be the same which was used initially to lock the item.
        :type lockhandle: LockHandle
        :param version: The version of the item to be removed. The item is removed from the cache only if this is still the most recent version in the cache.
        :type version: CacheItemVersion
        """

        ValidateType.is_string(key, self.delete)
        javakey = TypeCaster.to_java_primitive_type(key)

        if writethruoptions is not None:
                ValidateType.type_check(writethruoptions, WriteThruOptions, self.delete)
        if lockhandle is not None and version is not None:
                ValidateType.type_check(lockhandle, LockHandle, self.delete)
                ValidateType.type_check(version, CacheItemVersion, self.delete)

        if version is not None:
                javawritethruoptions = None
                javalockhandle = None
                
                if writethruoptions is not None:
                        javawritethruoptions = writethruoptions.get_instance()

                if lockhandle is not None:
                        javalockhandle = lockhandle.get_instance()

                javaversion = version.get_instance()
                self.__cache.delete(javakey, javalockhandle, javaversion, javawritethruoptions)
                
        elif version is None and lockhandle is None:
                javawritethruoptions = None
                if writethruoptions is not None:
                        javawritethruoptions = writethruoptions.get_instance()
                
                self.__cache.delete(javakey, javawritethruoptions)

        else:
                raise ValueError(ExceptionHandler.exceptionmessages.get("Cache.delete"))
def delete_async(self, key, writethruoptions=None)

위치를 참조하기 위해 캐시 키와 비동기적으로 캐시에서 항목을 삭제합니다.

:param key: 삭제할 항목의 고유 키입니다. :type key: str :param writethruoptions: 데이터 소스 업데이트에 관한 WriteThruOptions. WriteThru, WriteBehind 또는 None일 수 있습니다. :type writethruoptions: WriteThruOptions :return: 백그라운드에서 삭제 작업을 수행하는 작업 :rtype: 작업

소스 코드 확장
def delete_async(self, key, writethruoptions=None):
        """
        Deletes an item from the cache asynchronously with a cache key to reference its location.

        :param key:  Unique key of the item to be deleted.
        :type key: str
        :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WriteThru, WriteBehind or None.
        :type writethruoptions: WriteThruOptions
        :return: Task that performs a delete operation in the background
        :rtype: Task
        """
        return asyncio.create_task(self.__return_coroutine(self.delete, key, writethruoptions))
def delete_bulk(self, keys, writethruoptions=None)

캐시에서 지정된 항목을 삭제합니다. 캐시와 데이터 소스 모두에서 항목을 제거할 수 있도록 쓰기 옵션을 지정할 수도 있습니다.

:param keys: 삭제할 항목의 고유한 키 목록입니다. :type 키: 목록 :param writethruoptions: 데이터 소스 업데이트에 관한 WriteThruOptions. WriteThru, WriteBehind 또는 None일 수 있습니다. :writethruoptions 입력: WriteThruOptions

소스 코드 확장
def delete_bulk(self, keys, writethruoptions=None):
        """
        Deletes the specified items from the Cache. You can also specify the write option such that the items may be removed from both cache and data source.

        :param keys: Unique list of keys of the items to be deleted.
        :type keys: list
        :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WriteThru, WriteBehind or None.
        :type writethruoptions: WriteThruOptions
        """
        ValidateType.type_check(keys, list, self.delete_bulk)
        for key in keys:
                ValidateType.is_string(key, self.delete_bulk)
        javakeys = TypeCaster.to_java_array_list(keys, True)
        if writethruoptions is not None:
                ValidateType.type_check(writethruoptions, WriteThruOptions, self.delete_bulk)

        if writethruoptions is not None:
                javawritethruoptions = writethruoptions.get_instance()
                self.__cache.deleteBulk(javakeys, javawritethruoptions)
        else:
                self.__cache.deleteBulk(javakeys)
def get(self, key, objtype, readthruoptions=None, cacheitemversion=None, acquirelock=None, locktimeout=None, lockhandle=None)

Cache 개체에서 지정된 항목을 검색합니다.

:param key: 캐시 항목을 식별하는 고유 키입니다. :type key: str :param objtype: 캐시에서 검색할 항목의 유형 :type objtype: type :param readthruoptions: 데이터 소스에서 읽을 ReadThruOptions. 이는 ReadThru, ReadThruForced 또는 None일 수 있습니다. :type readthruoptions: ReadThruOptions :param acquirelock: 잠금을 획득할지 여부를 결정하는 플래그입니다. :type acquirelock: bool :param locktimeout: 잠금이 자동으로 해제된 이후의 TimeSpan입니다. :type locktimeout: TimeSpan :param lockhandle: 잠금 정보를 보관할 LockHandle의 인스턴스. :type lockhandle: LockHandle :param cacheitemversion: 객체의 버전. CacheItemVersion에 대해 None이 전달되면 캐시의 개체 버전이 반환됩니다. None이 아닌 CacheItemVersion이 전달되면 캐시에 있는 개체의 현재 버전인 경우에만 개체가 캐시에서 반환됩니다. :type cacheitemversion: CacheItemVersion :return: 검색된 캐시 항목 또는 키를 찾을 수 없는 경우 None 참조. :r타입: 객체

소스 코드 확장
def get(self, key, objtype, readthruoptions=None, cacheitemversion=None, acquirelock=None, locktimeout=None, lockhandle=None):
        """
        Retrieves the specified item from the Cache object.

        :param key: Unique key to identify the cache item.
        :type key: str
        :param objtype: Type of the item to be retrieved from cache
        :type objtype: type
        :param readthruoptions: ReadThruOptions to read from data source. These can be either ReadThru, ReadThruForced or None.
        :type readthruoptions: ReadThruOptions
        :param acquirelock: A flag to determine whether to acquire a lock or not.
        :type acquirelock: bool
        :param locktimeout: The TimeSpan after which the lock is automatically released.
        :type locktimeout: TimeSpan
        :param lockhandle: An instance of LockHandle to hold the lock information.
        :type lockhandle: LockHandle
        :param cacheitemversion: The version of the object. If None is passed for CacheItemVersion, then the version of the object from the cache is returned. If non-None CacheItemVersion is passed, then object is returned from the cache only if that is the current version of the object in the cache.
        :type cacheitemversion: CacheItemVersion
        :return: The retrieved cache item, or a None reference if the key is not found.
        :rtype: object
        """

        ValidateType.is_string(key, self.get)
        javakey = TypeCaster.to_java_primitive_type(key)

        ValidateType.type_check(objtype, type, self.get)

        if readthruoptions is not None:
                ValidateType.type_check(readthruoptions, ReadThruOptions, self.get)

        if locktimeout is not None and lockhandle is not None and acquirelock is not None:
                ValidateType.type_check(lockhandle, LockHandle, self.get)
                ValidateType.type_check(locktimeout, TimeSpan, self.get)
                ValidateType.type_check(acquirelock, bool, self.get)

        if cacheitemversion is not None:
                ValidateType.type_check(cacheitemversion, CacheItemVersion, self.get)

        pythontype, javatype = TypeCaster.is_java_primitive(objtype)

        usejsonconversoin = False
        if javatype is None:
                if isinstance(objtype(), collections.Collection):
                        javatype = JavaInstancesFactory.get_java_instance("JsonArray")
                else:
                        javatype = JavaInstancesFactory.get_java_instance("JsonObject")
                usejsonconversoin = True
        
        if cacheitemversion is not None:
                javacacheitemversion = cacheitemversion.get_instance()
                javareadthruoptions = None
                
                if readthruoptions is not None:
                        javareadthruoptions = readthruoptions.get_instance()

                result = self.__cache.get(javakey, javacacheitemversion, javareadthruoptions, javatype)

        elif locktimeout is not None and lockhandle is not None and acquirelock is not None:
                javalockhandle = lockhandle.get_instance()
                javalocktimeout = locktimeout.get_instance()
                javaacquirelock = TypeCaster.to_java_primitive_type(acquirelock)
                result = self.__cache.get(javakey, javaacquirelock, javalocktimeout, javalockhandle, javatype)

        elif locktimeout is None and lockhandle is None and acquirelock is None and cacheitemversion is None:
                javareadthruoptions = None
                
                if readthruoptions is not None:
                        javareadthruoptions = readthruoptions.get_instance()

                result = self.__cache.get(javakey, javareadthruoptions, javatype)

        else:
                raise ValueError(ExceptionHandler.exceptionmessages.get("Cache.get"))

        if result is not None:
                if not usejsonconversoin:
                        result = pythontype(result)
                else:
                        result = TypeCaster.deserialize(result, objtype, isjsonobject=True)
        return result
def get_bulk(self, keys, objtype, readthruoptions=None)

사전 형식의 키-값 쌍으로 지정된 키에 대해 캐시에서 개체를 검색합니다.

:param keys: 캐시에서 가져올 항목의 목록 키입니다. :type keys: list :param objtype: 캐시에서 검색할 항목의 유형 :type objtype: type :param readthruoptions: 데이터 소스에서 읽을 ReadThruOptions. 이는 ReadThru, ReadThruForced 또는 None일 수 있습니다. :type readthruoptions: ReadThruOptions :return: 키-값 쌍의 사전으로 검색된 캐시 항목. :rtype: 사전

소스 코드 확장
def get_bulk(self, keys, objtype, readthruoptions=None):
        """
        Retrieves the objects from cache for the given keys as key-value pairs in form of a Dictionary.

        :param keys: The list keys against which items are to be fetched from cache.
        :type keys: list
        :param objtype: Type of the item to be retrieved from cache
        :type objtype: type
        :param readthruoptions: ReadThruOptions to read from data source. These can be either ReadThru, ReadThruForced or None.
        :type readthruoptions: ReadThruOptions
        :return: The retrieved cache items as Dictionary of key-value pairs.
        :rtype: dict
        """
        ValidateType.type_check(objtype, type, self.get_bulk)
        ValidateType.type_check(keys, list, self.get_bulk)
        for key in keys:
                ValidateType.is_string(key, self.get_bulk)
        javakeys = TypeCaster.to_java_array_list(keys, True)

        pythontype, javatype = TypeCaster.is_java_primitive(objtype)

        if javatype is None:
                javatype = JavaInstancesFactory.get_java_instance("JsonObject")

        javareadthruoptions = None

        if readthruoptions is not None:
                ValidateType.type_check(readthruoptions, ReadThruOptions, self.get_bulk)
                javareadthruoptions = readthruoptions.get_instance()

        result = self.__cache.getBulk(javakeys, javareadthruoptions, javatype)

        if result is not None:
                return self.__bulk_result_to_dict(result, False, objtype)
def get_cacheitem(self, key, readthruoptions=None, cacheitemversion=None, acquirelock=None, locktimeout=None, lockhandle=None)

Cache 개체에서 지정된 CacheItem을 검색합니다.

:param key: 캐시 항목을 식별하는 고유 키입니다. :type key: str :param readthruoptions: 데이터 소스에서 읽기 위한 ReadThruOptions. 이는 ReadThru, ReadThruForced 또는 None일 수 있습니다. :type readthruoptions: ReadThruOptions :param acquirelock: 잠금을 획득할지 여부를 결정하는 플래그입니다. :type acquirelock: bool :param locktimeout: 잠금이 자동으로 해제된 이후의 TimeSpan입니다. :type locktimeout: TimeSpan :param lockhandle: 잠금 정보를 보관할 LockHandle의 인스턴스. :type lockhandle: LockHandle :param cacheitemversion: 객체의 버전. CacheItemVersion에 대해 None이 전달되면 캐시의 개체 버전이 반환됩니다. None이 아닌 CacheItemVersion이 전달되면 캐시에 있는 개체의 현재 버전인 경우에만 개체가 캐시에서 반환됩니다. :type cacheitemversion: CacheItemVersion :return: 검색된 CacheItem 또는 키를 찾을 수 없는 경우 None 참조. :rtype: 캐시 항목

소스 코드 확장
def get_cacheitem(self, key, readthruoptions=None, cacheitemversion=None, acquirelock=None, locktimeout=None, lockhandle=None):
        """
        Retrieves the specified CacheItem from the Cache object.

        :param key: Unique key to identify the cache item.
        :type key: str
        :param readthruoptions: ReadThruOptions to read from data source. These can be either ReadThru, ReadThruForced or None.
        :type readthruoptions: ReadThruOptions
        :param acquirelock: A flag to determine whether to acquire a lock or not.
        :type acquirelock: bool
        :param locktimeout: The TimeSpan after which the lock is automatically released.
        :type locktimeout: TimeSpan
        :param lockhandle: An instance of LockHandle to hold the lock information.
        :type lockhandle: LockHandle
        :param cacheitemversion: The version of the object. If None is passed for CacheItemVersion, then the version of
                the object from the cache is returned. If non-None CacheItemVersion is passed, then object is returned from
                the cache only if that is the current version of the object in the cache.
        :type cacheitemversion: CacheItemVersion
        :return: The retrieved CacheItem, or a None reference if the key is not found.
        :rtype: CacheItem
        """
        ValidateType.is_string(key, self.get_cacheitem)
        javakey = TypeCaster.to_java_primitive_type(key)
        if readthruoptions is not None:
                ValidateType.type_check(readthruoptions, ReadThruOptions, self.get_cacheitem)

        if cacheitemversion is not None:
                ValidateType.type_check(cacheitemversion, CacheItemVersion, self.get_cacheitem)

        if acquirelock is not None and lockhandle is not None and locktimeout is not None:
                ValidateType.type_check(acquirelock, bool, self.get_cacheitem)
                ValidateType.type_check(lockhandle, LockHandle, self.get_cacheitem)
                ValidateType.type_check(locktimeout, TimeSpan, self.get_cacheitem)

        if cacheitemversion is not None:
                javareadthruoptions = None
                
                if readthruoptions is not None:
                        javareadthruoptions = readthruoptions.get_instance()

                javacacheitemversion = cacheitemversion.get_instance()
                result = self.__cache.getCacheItem(javakey, javacacheitemversion, javareadthruoptions)

        elif acquirelock is not None and lockhandle is not None and locktimeout is not None:
                javaacquirelock = TypeCaster.to_java_primitive_type(acquirelock)
                javalockhandle = lockhandle.get_instance()
                javalocktimeout = locktimeout.get_instance()
                result = self.__cache.getCacheItem(javakey, javaacquirelock, javalocktimeout, javalockhandle)

        elif cacheitemversion is None and acquirelock is None and lockhandle is None and locktimeout is None:
                javareadthruoptions = None
                
                if readthruoptions is not None:
                        javareadthruoptions = readthruoptions.get_instance()

                result = self.__cache.getCacheItem(javakey, javareadthruoptions)

        else:
                raise ValueError(ExceptionHandler.exceptionmessages.get("Cache.get_cacheitem"))

        if result is not None:
                cacheitem = CacheItem()
                cacheitem.set_instance(result)
                return cacheitem

        return result
def get_cacheitem_bulk(self, keys, readthruoptions=None)

사전 형식의 키-값 쌍으로 지정된 키에 대해 캐시에서 CacheItems를 검색합니다.

:param keys: CacheItems를 캐시에서 가져올 키입니다. :type 키: 목록 :param readthruoptions: 데이터 소스에서 읽기 위한 ReadThruOptions. 이는 ReadThru, ReadThruForced 또는 None일 수 있습니다. :type readthruoptions: ReadThruOptions :return: 키-값 쌍의 사전으로 검색된 CacheItems. :rtype: 사전

소스 코드 확장
def get_cacheitem_bulk(self, keys, readthruoptions=None):
        """
        Retrieves the CacheItems from cache for the given keys as key-value pairs in form of a Dictionary.

        :param keys: The keys against which CacheItems are to be fetched from cache.
        :type keys: list
        :param readthruoptions: ReadThruOptions to read from data source. These can be either ReadThru, ReadThruForced or None.
        :type readthruoptions: ReadThruOptions
        :return: The retrieved CacheItems as Dictionary of key-value pairs.
        :rtype: dict
        """
        ValidateType.type_check(keys, list, self.get_cacheitem_bulk)
        for key in keys:
                ValidateType.is_string(key, self.get_cacheitem_bulk)
        javakeys = TypeCaster.to_java_array_list(keys, True)

        if readthruoptions is not None:
                ValidateType.type_check(readthruoptions, ReadThruOptions, self.get_cacheitem_bulk)
                javareadthruoptions = readthruoptions.get_instance()
                result = self.__cache.getCacheItemBulk(javakeys, javareadthruoptions)

        else:
                result = self.__cache.getCacheItemBulk(javakeys)

        if result is not None:
                return self.__bulk_result_to_dict(result, iscacheitem=True)
def get_count(self)

캐시에 저장된 항목 수를 가져옵니다.

:return: 캐시에 저장된 항목 수입니다. :r타입: 정수

소스 코드 확장
def get_count(self):
        """
        Gets the number of items stored in the cache

        :return: The number of items stored in the cache.
        :rtype: int
        """
        result = self.__cache.getCount()

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

        return result
def get_data_structures_manager(self)

DataStructureManager의 인스턴스를 가져옵니다.

:return: DataStructureManager의 인스턴스 :rtype: DataStructureManager

소스 코드 확장
def get_data_structures_manager(self):
        """
        Gets an instance of DataStructureManager.

        :return: An instance of DataStructureManager
        :rtype: DataStructureManager
        """
        result = self.__cache.getDataStructuresManager()

        if result is not None:
                result = DataStructureManager(result)

        return result
def get_if_newer(self, key, cacheitemversion, objtype)

최신 버전의 개체가 캐시에 있는 경우에만 캐시에서 개체를 가져옵니다.

:param key: 원하는 개체를 참조하는 데 사용되는 고유 키입니다. :type key: str :param cacheitemversion: 개체의 CacheItemVersion입니다. :type cacheitemversion: CacheItemVersion :param objtype: 캐시에서 제거할 항목의 유형 :type objtype: type :return: 캐시에 새 개체가 있으면 해당 개체가 반환됩니다. 그렇지 않으면 None이 반환됩니다. :rtype: 객체 또는 없음

소스 코드 확장
def get_if_newer(self, key, cacheitemversion, objtype):
        """
        Gets an object from the cache only if a newer version of the object exists in cache.

        :param key: Unique key used to reference the desired object.
        :type key: str
        :param cacheitemversion: The CacheItemVersion of the object.
        :type cacheitemversion: CacheItemVersion
        :param objtype: Type of the item to be removed from cache
        :type objtype: type
        :return: If a newer object exists in the cache, the object is returned. Otherwise, None is returned.
        :rtype: object or None
        """
        ValidateType.is_string(key, self.get_if_newer)
        ValidateType.type_check(cacheitemversion, CacheItemVersion, self.get_if_newer)
        ValidateType.type_check(objtype, type, self.get_if_newer)

        javakey = TypeCaster.to_java_primitive_type(key)
        javacacheitemversion = cacheitemversion.get_instance()
        pythontype, javatype = TypeCaster.is_java_primitive(objtype)

        usejsonconversoin = False
        if javatype is None:
                if isinstance(objtype(), collections.Collection):
                        javatype = JavaInstancesFactory.get_java_instance("JsonArray")
                else:
                        javatype = JavaInstancesFactory.get_java_instance("JsonObject")
                usejsonconversoin = True

        result = self.__cache.getIfNewer(javakey, javacacheitemversion, javatype)

        if result is not None:
                if not usejsonconversoin:
                        result = pythontype(result)
                else:
                        result = TypeCaster.deserialize(result, objtype, isjsonobject=True)
        return result
def get_if_newer_cacheitem(self, key, cacheitemversion)

최신 버전의 개체가 캐시에 있는 경우에만 캐시에서 개체를 가져옵니다.

:param key: 원하는 개체를 참조하는 데 사용되는 고유 키입니다. :type key: str :param cacheitemversion: 개체의 CacheItemVersion입니다. :type cacheitemversion: CacheItemVersion :return: 캐시에 최신 CacheItem이 있으면 CacheItem이 반환됩니다. 그렇지 않으면 None이 반환됩니다. :rtype: CacheItem 또는 없음

소스 코드 확장
def get_if_newer_cacheitem(self, key, cacheitemversion):
        """
        Gets an object from the cache only if a newer version of the object exists in cache.

        :param key: Unique key used to reference the desired object.
        :type key: str
        :param cacheitemversion: The CacheItemVersion of the object.
        :type cacheitemversion: CacheItemVersion
        :return: If a newer CacheItem exists in the cache, the CacheItem is returned. Otherwise, None is returned.
        :rtype: CacheItem or None
        """
        ValidateType.is_string(key, self.get_cacheitem)
        ValidateType.type_check(cacheitemversion, CacheItemVersion, self.get_if_newer_cacheitem)

        javacacheitemversion = cacheitemversion.get_instance()
        javakey = TypeCaster.to_java_primitive_type(key)

        result = self.__cache.getIfNewerCacheItem(javakey, javacacheitemversion)

        if result is not None:
                cacheitem = CacheItem()
                cacheitem.set_instance(result)
                return cacheitem

        return result
def get_instance(self)
소스 코드 확장
def get_instance(self):
        return self.__cache
def get_messaging_service(self)

MessagingService의 인스턴스를 가져옵니다.

:return: MessagingService의 인스턴스 :rtype: MessagingService

소스 코드 확장
def get_messaging_service(self):
        """
        Gets an instance of MessagingService

        :return: An instance of MessagingService
        :rtype: MessagingService
        """
        result = self.__cache.getMessagingService()

        if result is not None:
                result = MessagingService(result)

        return result
def get_notification_service(self)

NotificationService의 인스턴스를 가져옵니다.

:return: NotificationService의 인스턴스 :rtype: NotificationService

소스 코드 확장
def get_notification_service(self):
        """
        Gets an instance of NotificationService

        :return: An instance of NotificationService
        :rtype: NotificationService
        """

        result = self.__cache.getNotificationService()

        if result is not None:
                result = NotificationService(result)

        return result
def get_search_service(self)

SearchService의 인스턴스를 가져옵니다.

:return: SearchService의 인스턴스 :rtype: SearchService

소스 코드 확장
def get_search_service(self):
        """
        Gets an instance of SearchService.

        :return: An instance of SearchService
        :rtype: SearchService
        """
        result = self.__cache.getSearchService()

        if result is not None:
                result = SearchService(result)

        return result
def insert(self, key, item, writethruoptions=None, lockhandle=None, releaselock=None)

항목 또는 CacheItem을 캐시에 삽입합니다.

:param key: 캐시 항목을 식별하는 고유 키입니다. :type key: str :param item: 캐시에 삽입될 값 또는 CacheItem. :type item: object 또는 CacheItem :param writethruoptions: 데이터 소스 업데이트에 관한 WriteThruOptions. WriteThru, WriteBehind 또는 None일 수 있습니다. :type writethruoptions: WriteThruOptions :param lockhandle: 잠금 정보를 보유하는 LockHandle의 인스턴스. 항목이 잠겨 있으면 올바른 lockHandle이 지정된 경우에만 항목을 업데이트할 수 있습니다. :type lockhandle: LockHandle :param releaselock: 작업 수행 후 잠금을 해제할지 여부를 결정하는 플래그입니다. :type releaselock: bool :return: 각 캐시 항목의 버전을 나타냅니다. :rtype: CacheItemVersion

소스 코드 확장
def insert(self, key, item, writethruoptions=None, lockhandle=None, releaselock=None):
        """
        Inserts an item or a CacheItem to the cache.

        :param key: Unique key to identify the cache item.
        :type key: str
        :param item: The value or the CacheItem that is to be inserted into the cache.
        :type item: object or CacheItem
        :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WriteThru, WriteBehind or None.
        :type writethruoptions: WriteThruOptions
        :param lockhandle: An instance of LockHandle that holds the lock information. If the item is locked, then it can only be updated if the correct lockHandle is specified.
        :type lockhandle: LockHandle
        :param releaselock: A flag to determine whether or not the lock should be released after operation is performed.
        :type releaselock: bool
        :return: Represents the version of each cache item.
        :rtype: CacheItemVersion
        """

        ValidateType.is_key_value_valid(key, item, self.insert)
        if writethruoptions is not None:
                ValidateType.type_check(writethruoptions, WriteThruOptions, self.insert)

        if lockhandle is not None and releaselock is not None:
                ValidateType.type_check(lockhandle, LockHandle, self.insert)
                ValidateType.type_check(releaselock, bool, self.insert)

        javatype = TypeCaster.is_python_primitive(item)

        javakey = TypeCaster.to_java_primitive_type(key)

        if javatype is not None:
                if writethruoptions is not None or lockhandle is not None or releaselock is not None:
                        raise TypeError(ExceptionHandler.get_invalid_cache_insert_exception_message(CacheItem))
                res = self.__cache.insert(javakey, javatype)

        elif isinstance(item, CacheItem):
                value = item.get_instance()

                if lockhandle is not None and releaselock is not None:
                        javawritethruoptions = None
                        
                        if writethruoptions is not None:
                                javawritethruoptions = writethruoptions.get_instance()
                        
                        javalockhandle = lockhandle.get_instance()
                        javareleaselock = TypeCaster.to_java_primitive_type(releaselock)
                        res = self.__cache.insert(javakey, value, javawritethruoptions, javalockhandle, javareleaselock)

                elif lockhandle is not None or releaselock is not None:
                        raise ValueError(ExceptionHandler.exceptionmessages.get("Cache.insert"))

                else:
                        javawritethruoptions = None
                        
                        if writethruoptions is not None:
                                javawritethruoptions = writethruoptions.get_instance()
                                
                        res = self.__cache.insert(javakey, value, javawritethruoptions)

        else:
                if writethruoptions is not None or lockhandle is not None or releaselock is not None:
                        raise ValueError(ExceptionHandler.exceptionmessages.get("Cache.insert"))
                value = TypeCaster.serialize(item, isjsonobject=True, verbose=True)
                res = self.__cache.insert(javakey, value)

        if res is not None:
                return CacheItemVersion(int(res.getVersion()))
def insert_async(self, key, item, writethruoptions=None)

항목 또는 CacheItem을 해당 위치를 참조하는 캐시 키와 WriteThruOptions를 사용하거나 사용하지 않고 캐시에 비동기적으로 삽입합니다.

:param key: 캐시 항목을 식별하는 고유 키입니다. :type key: str :param item: 캐시에 저장될 항목(객체) 또는 CacheItem. :type item: object :param writethruoptions: 데이터 소스 업데이트에 관한 WriteThruOptions. WriteThru, WriteBehind 또는 None일 수 있습니다. :type writethruoptions: WriteThruOptions :return: 백그라운드에서 삽입 작업을 수행하는 태스크. :rtype: 작업

소스 코드 확장
def insert_async(self, key, item, writethruoptions=None):
        """
        Inserts an item or a CacheItem to the cache asynchronously with a cache key to reference its location and with or without WriteThruOptions.

        :param key: Unique key to identify the cache item.
        :type key: str
        :param item: The item (object) or CacheItem to be stored in the cache.
        :type item: object
        :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WriteThru, WriteBehind or None.
        :type writethruoptions: WriteThruOptions
        :return: Task that performs an insert operation in the background.
        :rtype: Task
        """
        return asyncio.create_task(self.__return_coroutine(self.insert, key, item, writethruoptions))
def insert_bulk(self, items, writethruoptions=None)

CacheItem이 있는 캐시 키의 사전을 WriteThruOptions를 사용하거나 사용하지 않고 캐시에 삽입합니다.

:param items: 키와 CacheItem의 사전. 키는 고유해야 합니다. :type items: dict :param writethruoptions: 데이터 소스 업데이트에 관한 WriteThruOptions. WriteThru, WriteBehind 또는 None일 수 있습니다. :type writethruoptions: WriteThruOptions :return: 캐시에 저장할 수 없는 항목에 대한 예외와 함께 키 사전. :rtype: 사전

소스 코드 확장
def insert_bulk(self, items, writethruoptions=None):
        """
        Inserts a Dictionary of cache keys with CacheItem to the cache with or without the WriteThruOptions.

        :param items: Dictionary of keys and CacheItem. Keys must be unique.
        :type items: dict
        :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WriteThru, WriteBehind or None.
        :type writethruoptions: WriteThruOptions
        :return: Dictionary of Keys along with Exception for items that were unable to store in cache.
        :rtype: dict
        """
        ValidateType.type_check(items, dict, self.insert_bulk)
        for item in items:
                ValidateType.is_string(item, self.insert_bulk)
                ValidateType.type_check(items[item], CacheItem, self.insert_bulk)
        javaitems = TypeCaster.to_java_hash_map(items, False)

        if writethruoptions is not None:
                ValidateType.type_check(writethruoptions, WriteThruOptions, self.insert_bulk)
                javawritethruoptions = writethruoptions.get_instance()

                result = self.__cache.insertBulk(javaitems, javawritethruoptions)
        else:
                result = self.__cache.insertBulk(javaitems)

        if result is not None:
                return self.__bulk_result_to_dict(result, True)
def lock(self, key, locktimeout, lockhandle)

캐시의 항목에 대한 잠금을 획득합니다.

:param key: 잠글 캐시된 항목의 키입니다. :type key:str :param locktimeout: 잠금이 자동으로 해제되는 TimeSpan의 인스턴스. :type locktimeout: TimeSpan :param lockhandle: 잠금이 성공적으로 획득되면 잠금 정보로 채워질 LockHandle의 인스턴스. :type lockhandle: LockHandle :return: 잠금이 성공적으로 획득되었는지 여부. :r타입: 부울

소스 코드 확장
def lock(self, key, locktimeout, lockhandle):
        """
        Acquires a lock on an item in the cache.

        :param key: Key of cached item to be locked.
        :type key:str
        :param locktimeout: An instance of TimeSpan after which the lock is automatically released.
        :type locktimeout: TimeSpan
        :param lockhandle: An instance of LockHandle that will be filled in with the lock information if lock is acquired successfully.
        :type lockhandle: LockHandle
        :return: Whether or not lock was acquired successfully.
        :rtype: bool
        """
        ValidateType.is_string(key, self.lock)
        ValidateType.type_check(lockhandle, LockHandle, self.lock)
        ValidateType.type_check(locktimeout, TimeSpan, self.lock)

        javakey = TypeCaster.to_java_primitive_type(key)
        javalocktimeout = locktimeout.get_instance()
        javalockhandle = lockhandle.get_instance()

        result = self.__cache.lock(javakey, javalocktimeout, javalockhandle)

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

        return result
def remove(self, key, objtype, writethruoptions=None, lockhandle=None, version=None)

캐시에서 지정된 키가 있는 항목을 제거하고 검색합니다.

:param key: 삭제할 항목의 고유 키입니다. :type key: str :param writethruoptions: 데이터 소스 업데이트에 관한 WriteThruOptions. 이것은 다음 중 하나일 수 있습니다. lockhandle은 처음에 항목을 잠그는 데 사용된 것과 동일해야 합니다. :type lockhandle: LockHandle :param version: 제거할 항목의 버전. 캐시에서 여전히 최신 버전인 경우에만 항목이 캐시에서 제거됩니다. :type version: CacheItemVersion :return: 키가 존재하면 제거된 항목, 그렇지 않으면 None이 반환됩니다. :r타입: 객체

소스 코드 확장
def remove(self, key, objtype, writethruoptions=None, lockhandle=None, version=None):
        """
        Removes and retrieves the item with the specified key from cache.

        :param key: Unique key of the item to be deleted.
        :type key: str
        :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either
        :type writethruoptions: WriteThruOptions
        :param objtype: Type of the item to be removed from cache
        :type objtype: type
        :param lockhandle: If the item is locked, it can be removed only if the correct lockhandle is specified. lockhandle should be the same which was used initially to lock the item.
        :type lockhandle: LockHandle
        :param version: The version of the item to be removed. The item is removed from the cache only if this is still the most recent version in the cache.
        :type version: CacheItemVersion
        :return: The removed item if the key exists otherwise None is returned.
        :rtype: object
        """

        ValidateType.is_string(key, self.remove)
        javakey = TypeCaster.to_java_primitive_type(key)

        if writethruoptions is not None:
                ValidateType.type_check(writethruoptions, WriteThruOptions, self.remove)
        if lockhandle is not None and version is not None:
                ValidateType.type_check(lockhandle, LockHandle, self.remove)
                ValidateType.type_check(version, CacheItemVersion, self.remove)

        pythontype, javatype = TypeCaster.is_java_primitive(objtype)
        usejsonconversoin = False

        if javatype is None:
                if isinstance(objtype(), collections.Collection):
                        javatype = JavaInstancesFactory.get_java_instance("JsonArray")
                else:
                        javatype = JavaInstancesFactory.get_java_instance("JsonObject")
                usejsonconversoin = True

        if version is not None:
                javawritethruoptions = None
                javalockhandle = None

                if writethruoptions is not None:
                        javawritethruoptions = writethruoptions.get_instance()

                if lockhandle is not None:
                        javalockhandle = lockhandle.get_instance()

                javaversion = version.get_instance()
                result = self.__cache.remove(javakey, javalockhandle, javaversion, javawritethruoptions, javatype)

        elif lockhandle is not None:
                javalockhandle = lockhandle.get_instance()
                javawritethruoptions = None
                javaversion = None

                if version is not None:
                        javaversion = version.get_instance()

                if writethruoptions is not None:
                        javawritethruoptions = writethruoptions.get_instance()

                result = self.__cache.remove(javakey, javalockhandle, javaversion, javawritethruoptions, javatype)
        elif lockhandle is None and version is None:
                javawritethruoptions = None
                
                if writethruoptions is not None:
                        javawritethruoptions = writethruoptions.get_instance()

                result = self.__cache.remove(javakey, javawritethruoptions, javatype)

        else:
                raise ValueError(ExceptionHandler.exceptionmessages.get("Cache.remove"))

        if result is not None:
                if not usejsonconversoin:
                        result = pythontype(result)
                else:
                        result = TypeCaster.deserialize(result, objtype, isjsonobject=True)
        return result
def remove_async(self, key, objtype, writethruoptions=None)

위치를 참조하는 캐시 키로 캐시에서 항목을 비동기식으로 제거합니다.

:param key: 삭제할 항목의 고유 키입니다. :type key: str :param objtype: 캐시에서 제거할 항목의 유형 :type objtype: type :param writethruoptions: 데이터 소스 업데이트에 관한 WriteThruOptions. WriteThru, WriteBehind 또는 None일 수 있습니다. :type writethruoptions: WriteThruOptions :return: 백그라운드에서 제거 작업을 수행하는 작업입니다. 완료되면 제거된 캐시 항목 반환 :rtype: 작업

소스 코드 확장
def remove_async(self, key, objtype, writethruoptions=None):
        """
        Removes an item from the cache asynchronously with a cache key to reference its location.

        :param key:  Unique key of the item to be deleted.
        :type key: str
        :param objtype: Type of the item to be removed from cache
        :type objtype: type
        :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WriteThru, WriteBehind or None.
        :type writethruoptions: WriteThruOptions
        :return: Task that performs a remove operation in the background. Once completed returns the removed cache item
        :rtype: Task
        """
        return asyncio.create_task(self.__return_coroutine(self.remove, key, objtype, writethruoptions))
def remove_bulk(self, keys, objtype, writethruoptions=None)

캐시에서 지정된 항목을 제거하고 사전 형식으로 응용 프로그램에 반환합니다.

:param keys: 제거할 항목의 고유 키 목록입니다. :type keys: list :param objtype: 캐시에서 검색할 항목의 유형 :type objtype: type :param writethruoptions: 데이터 소스 업데이트에 관한 WriteThruOptions. WRITE_THRU, WRITE_BEHIND 또는 NONE일 수 있습니다. :type writethruoptions: WriteThruOptions :return: 사전 형식으로 캐시에서 제거된 항목. :rtype: 사전

소스 코드 확장
def remove_bulk(self, keys, objtype, writethruoptions=None):
        """
        Removes the specified items from the Cache and returns them to the application in the form of a Dictionary.

        :param keys: List of Unique keys of the item to be removed.
        :type keys: list
        :param objtype: Type of the item to be retrieved from cache
        :type objtype: type
        :param writethruoptions: WriteThruOptions regarding updating the data source. This can be either WRITE_THRU, WRITE_BEHIND or NONE.
        :type writethruoptions: WriteThruOptions
        :return: The removed items from cache in form of a Dictionary.
        :rtype: dict
        """
        ValidateType.type_check(keys, list, self.remove_bulk)
        for key in keys:
                ValidateType.is_string(key, self.remove_bulk)

        ValidateType.type_check(objtype, type, self.remove_bulk)
        pythontype, javatype = TypeCaster.is_java_primitive(objtype)

        if javatype is None:
                javatype = JavaInstancesFactory.get_java_instance("JsonObject")

        javakeys = TypeCaster.to_java_array_list(keys, True)
        if writethruoptions is not None:
                ValidateType.type_check(writethruoptions, WriteThruOptions, self.remove_bulk)
                javawritethruoptions = writethruoptions.get_instance()

                result = self.__cache.removeBulk(javakeys, javawritethruoptions, javatype)
        else:
                result = self.__cache.removeBulk(javakeys, javatype)

        return self.__bulk_result_to_dict(result, False, objtype)
def set_instance(self, value)
소스 코드 확장
def set_instance(self, value):
        self.__cache = value
def unlock(self, key, lockhandle=None)

올바른 잠금 핸들이 제공된 경우 잠긴 캐시 항목의 잠금을 해제합니다. 잠금 핸들이 제공되지 않으면 항목을 강제로 잠금 해제합니다.

:param key: 잠금 해제할 캐시된 항목의 키입니다. :type key: str :param lockhandle: 잠금을 획득할 때 생성되는 LockHandle의 인스턴스. :lockhandle 유형: LockHandle

소스 코드 확장
def unlock(self, key, lockhandle=None):
        """
        Unlocks a locked cached item if the correct lockhandle is provided. Forcefully unlocks the item if no lockhandle is provided.

        :param key: Key of the cached item to be unlocked.
        :type key: str
        :param lockhandle: An instance of LockHandle that is generated when the lock is acquired.
        :type lockhandle: LockHandle
        """
        ValidateType.is_string(key, self.unlock)
        javakey = TypeCaster.to_java_primitive_type(key)

        if lockhandle is not None:
                ValidateType.type_check(lockhandle, LockHandle, self.unlock)
                javalockhandle = lockhandle.get_instance()

                self.__cache.unlock(javakey, javalockhandle)

        else:
                self.__cache.unlock(javakey)
def update_attributes(self, key, attributes)

캐시에 있는 기존 항목의 CacheItemAttributes를 업데이트합니다.

:param key: 캐시 항목을 식별하는 고유 키입니다. :type 키: str :param 속성: 캐시에서 항목을 업데이트하기 위한 CacheItemAttributes의 인스턴스. :type 속성: CacheItemAttributes :return: 업데이트 작업의 상태를 결정하는 플래그. 캐시에 있는 항목의 속성이 성공적으로 업데이트된 경우 True이고 그렇지 않으면 False입니다. :r타입: 부울

소스 코드 확장
def update_attributes(self, key, attributes):
        """
        Update CacheItemAttributes of an existing item in cache.

        :param key: Unique key to identify the cache item.
        :type key: str
        :param attributes: An instance of CacheItemAttributes to update item in the cache.
        :type attributes: CacheItemAttributes
        :return: Flag that determines status of the update operation. True if attributes of the item in cache was updated successfully otherwise False.
        :rtype: bool
        """
        ValidateType.is_string(key, self.update_attributes)
        ValidateType.type_check(attributes, CacheItemAttributes, self.update_attributes)

        javakey = TypeCaster.to_java_primitive_type(key)
        javaattributes = attributes.get_instance()

        result = self.__cache.updateAttributes(javakey, javaattributes)

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

        return result