:right-sidebar: True Cache =================================================================== .. currentmodule:: gi.repository.GLib .. deprecated:: 2.32 Use a :obj:`~gi.repository.GLib.HashTable` instead .. class:: Cache(*args, **kwargs) :no-contents-entry: A ``GCache`` allows sharing of complex data structures, in order to save system resources. ``GCache`` uses keys and values. A ``GCache`` key describes the properties of a particular resource. A ``GCache`` value is the actual resource. ``GCache`` has been marked as deprecated, since this API is rarely used and not very actively maintained. Methods ------- .. rst-class:: interim-class .. class:: Cache :no-index: .. method:: destroy() -> None Frees the memory allocated for the :obj:`~gi.repository.GLib.Cache`\. Note that it does not destroy the keys and values which were contained in the :obj:`~gi.repository.GLib.Cache`\. .. deprecated:: 2.32 Use a :obj:`~gi.repository.GLib.HashTable` instead .. method:: insert(key: ~typing.Any = None) -> ~typing.Any | None Gets the value corresponding to the given key, creating it if necessary. It first checks if the value already exists in the :obj:`~gi.repository.GLib.Cache`\, by using the ``key_equal_func`` function passed to :func:`~gi.repository.GLib.Cache.new`. If it does already exist it is returned, and its reference count is increased by one. If the value does not currently exist, if is created by calling the ``value_new_func``\. The key is duplicated by calling ``key_dup_func`` and the duplicated key and value are inserted into the :obj:`~gi.repository.GLib.Cache`\. .. deprecated:: 2.32 Use a :obj:`~gi.repository.GLib.HashTable` instead :param key: a key describing a :obj:`~gi.repository.GLib.Cache` object .. method:: key_foreach(func: ~typing.Callable[[~typing.Any, ~typing.Any, ~typing.Any], None], user_data: ~typing.Any = None) -> None Calls the given function for each of the keys in the :obj:`~gi.repository.GLib.Cache`\. NOTE ``func`` is passed three parameters, the value and key of a cache entry and the ``user_data``\. The order of value and key is different from the order in which :func:`~gi.repository.GLib.HashTable.foreach` passes key-value pairs to its callback function ! .. deprecated:: 2.32 Use a :obj:`~gi.repository.GLib.HashTable` instead :param func: the function to call with each :obj:`~gi.repository.GLib.Cache` key :param user_data: user data to pass to the function .. method:: remove(value: ~typing.Any = None) -> None Decreases the reference count of the given value. If it drops to 0 then the value and its corresponding key are destroyed, using the ``value_destroy_func`` and ``key_destroy_func`` passed to :func:`~gi.repository.GLib.Cache.new`. .. deprecated:: 2.32 Use a :obj:`~gi.repository.GLib.HashTable` instead :param value: the value to remove :return: 0 if the file was successfully removed, -1 if an error occurred .. method:: value_foreach(func: ~typing.Callable[[~typing.Any, ~typing.Any, ~typing.Any], None], user_data: ~typing.Any = None) -> None Calls the given function for each of the values in the :obj:`~gi.repository.GLib.Cache`\. .. deprecated:: 2.10 The reason is that it passes pointers to internal data structures to ``func``\; use :func:`~gi.repository.GLib.Cache.key_foreach` instead :param func: the function to call with each :obj:`~gi.repository.GLib.Cache` value :param user_data: user data to pass to the function