◆ fiftyoneDegreesCacheHashCodeMethod
typedef int64_t(* fiftyoneDegreesCacheHashCodeMethod) (const void *key) |
Method used to calculate a hash code from the key.
- Parameters
-
- key - the data to be calculate the integer key.
- Returns
- 64 bit representation of the key data.
◆ fiftyoneDegreesCacheLoadMethod
typedef void(* fiftyoneDegreesCacheLoadMethod) (const void *state, fiftyoneDegreesData *data, const void *key, fiftyoneDegreesException *exception) Method used to load data into the cache.
- Parameters
-
- state - information used for the load operation.
- data - structure to be used to store the data loaded.
- key - for the item in the collection to be loaded.
- exception - pointer to an exception data structure to be used if an exception occurs. See exceptions.h.
Function Documentation
◆ fiftyoneDegreesCacheCreate()
fiftyoneDegreesCache* fiftyoneDegreesCacheCreate ( uint32_t capacity, uint16_t concurrency, fiftyoneDegreesCacheLoadMethod load, fiftyoneDegreesCacheHashCodeMethod hash, const void * state ) Creates a new cache.The cache must be destroyed with the fiftyoneDegreesCacheFree method.
- Parameters
-
- capacity - maximum number of items that the cache should store
- concurrency - the expected number of parallel operations
- load - pointer to method used to load an entry into the cache
- hash - pointer to a method used to hash the key into a int64_t
- state - pointer to state information to pass to the load method
- Returns
- a pointer to the cache created, or NULL if one was not created.
◆ fiftyoneDegreesCacheFree()
void fiftyoneDegreesCacheFree ( fiftyoneDegreesCache * cache ) Frees the cache structure, all allocated nodes and their data.
- Parameters
-
- cache - to be freed
◆ fiftyoneDegreesCacheGet()
fiftyoneDegreesCacheNode* fiftyoneDegreesCacheGet ( fiftyoneDegreesCache * cache, const void * key, fiftyoneDegreesException * exception ) Gets an item from the cache.
If an item is not in the cache, it is loaded using the loader the cache was initialized with.
The cache being used as a loading cache must have a load method defined which returns a pointer to the data relating to the key used. This method may, or may not, allocate memory or free memory previously allocated to data in the cache node.
Nodes fetched from the cache are protected from modification until all references to them are released. This means that the size of the cache must be carefully chosen to be no smaller than the maximum number of nodes which may be in use at any one time. Attempting to fetch a node when there are no free nodes to load the data into will result in a null being returned.
- Parameters
-
- cache - to get the entry from
- key - for the item to be returned
- exception - pointer to an exception data structure to be used if an exception occurs. See exceptions.h.
- Returns
- pointer to the requested item or null if too many items have been fetched and not released or the key is not valid
◆ fiftyoneDegreesCacheHash32()
int64_t fiftyoneDegreesCacheHash32 ( const void * key ) Passed a pointer to a 32 bit / 4 byte data structure and returns the data as a 64 bit / 8 byte value for use in the cache.
Used when cache keys are 32 bit integers.
- Parameters
-
- key - to be used in the cache
- Returns
- key represented as a 64 bit integer
◆ fiftyoneDegreesCacheHash64()
int64_t fiftyoneDegreesCacheHash64 ( const void * key ) Passed a pointer to a 64 bit / 8 byte data structure and returns the data as a 64 bit / 8 byte value for use in the cache.
Used when cache keys are 64 bit integers.
- Parameters
-
- key - to be used in the cache
- Returns
- key represented as a 64 bit integer
◆ fiftyoneDegreesCacheRelease()
void fiftyoneDegreesCacheRelease ( fiftyoneDegreesCacheNode * node ) Releases the cache node previous obtained via fiftyoneDegreesCacheGet so that it can be evicted from the cache if needed.
- Parameters
-
- node - to be released.