Cache#
Deprecated since version 2.32: Use a HashTable instead
- class Cache(*args, **kwargs)#
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#
- class Cache
- destroy() None#
Frees the memory allocated for the
Cache.Note that it does not destroy the keys and values which were contained in the
Cache.Deprecated since version 2.32: Use a
HashTableinstead
- insert(key: Any = None) Any | None#
Gets the value corresponding to the given key, creating it if necessary. It first checks if the value already exists in the
Cache, by using thekey_equal_funcfunction passed tonew(). 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 thevalue_new_func. The key is duplicated by callingkey_dup_funcand the duplicated key and value are inserted into theCache.Deprecated since version 2.32: Use a
HashTableinstead- Parameters:
key – a key describing a
Cacheobject
- key_foreach(func: Callable[[Any, Any, Any], None], user_data: Any = None) None#
Calls the given function for each of the keys in the
Cache.NOTE
funcis passed three parameters, the value and key of a cache entry and theuser_data. The order of value and key is different from the order in whichforeach()passes key-value pairs to its callback function !Deprecated since version 2.32: Use a
HashTableinstead- Parameters:
func – the function to call with each
Cachekeyuser_data – user data to pass to the function
- remove(value: 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_funcandkey_destroy_funcpassed tonew().Deprecated since version 2.32: Use a
HashTableinstead- Parameters:
value – the value to remove
- Returns:
0 if the file was successfully removed, -1 if an error occurred
- value_foreach(func: Callable[[Any, Any, Any], None], user_data: Any = None) None#
Calls the given function for each of the values in the
Cache.Deprecated since version 2.10:
- The reason is that it passes pointers to internal
data structures to
func; usekey_foreach()instead
- Parameters:
func – the function to call with each
Cachevalueuser_data – user data to pass to the function