lv_cache.h

API reference for lv_cache.h

Report on GitHub

Functions

lv_cache_set_max_size

Set the maximum size of the cache. If the current cache size is greater than the new maximum size, the cache's policy will be used to evict entries until the new maximum size is reached. If set to 0, the cache will be disabled.

 
void lv_cache_set_max_size(lv_cache_t *cache, size_t max_size, void *user_data)
Parameters
NameTypeDescription
cachelv_cache_t *The cache object pointer to set the maximum size.
max_sizesize_tThe new maximum size of the cache.
user_datavoid *A user data pointer that will be passed to the free callback. May be NULL.

But this behavior will happen only new entries are added to the cache.

lv_cache_set_compare_cb

Set the compare callback of the cache.

 
void lv_cache_set_compare_cb(lv_cache_t *cache, lv_cache_compare_cb_t compare_cb, void *user_data)
Parameters
NameTypeDescription
cachelv_cache_t *The cache object pointer to set the compare callback.
compare_cblv_cache_compare_cb_tThe compare callback to set.
user_datavoid *A user data pointer. May be NULL.

lv_cache_set_create_cb

Set the create callback of the cache.

 
void lv_cache_set_create_cb(lv_cache_t *cache, lv_cache_create_cb_t alloc_cb, void *user_data)
Parameters
NameTypeDescription
cachelv_cache_t *The cache object pointer to set the create callback.
alloc_cblv_cache_create_cb_tThe create callback to set.
user_datavoid *A user data pointer. May be NULL.

lv_cache_set_free_cb

Set the free callback of the cache.

 
void lv_cache_set_free_cb(lv_cache_t *cache, lv_cache_free_cb_t free_cb, void *user_data)
Parameters
NameTypeDescription
cachelv_cache_t *The cache object pointer to set the free callback.
free_cblv_cache_free_cb_tThe free callback to set.
user_datavoid *A user data pointer. May be NULL.

lv_cache_set_name

Give a name for a cache object. Only the pointer of the string is saved.

 
void lv_cache_set_name(lv_cache_t *cache, const char *name)
Parameters
NameTypeDescription
cachelv_cache_t *The cache object pointer to set the name.
nameconst char *The name of the cache.

Enums

lv_cache_reserve_cond_res_t

The result of the cache reserve condition callback

NameDescription
LV_CACHE_RESERVE_COND_OKThe condition is met and no entries need to be evicted
LV_CACHE_RESERVE_COND_TOO_LARGEThe condition is not met and the reserve size is too large
LV_CACHE_RESERVE_COND_NEED_VICTIMThe condition is not met and a victim is needed to be evicted
LV_CACHE_RESERVE_COND_ERRORAn error occurred while checking the condition

Structs

struct

_lv_cache_ops_t

The cache operations struct

MemberTypeDescription
compare_cblv_cache_compare_cb_tCompare function for keys
create_cblv_cache_create_cb_tCreate function for nodes
free_cblv_cache_free_cb_tFree function for nodes
struct

_lv_cache_t

The cache entry struct

MemberTypeDescription
clzconst lv_cache_class_t *Cache class. There are two built-in classes:
- lv_cache_class_lru_rb_count for LRU-based cache with count-based eviction policy.
- lv_cache_class_lru_rb_size for LRU-based cache with size-based eviction policy.
node_sizeuint32_tSize of a node
max_sizeuint32_tMaximum size of the cache
sizeuint32_tCurrent size of the cache
opslv_cache_ops_tCache operations struct _lv_cache_ops_t
locklv_mutex_tCache lock used to protect the cache in multithreading environments
nameconst char *Name of the cache
struct

_lv_cache_class_t

Cache class struct for building custom cache classes

Examples:

  • lv_cache_class_lru_rb_count for LRU-based cache with count-based eviction policy.
  • lv_cache_class_lru_rb_size for LRU-based cache with size-based eviction policy.
MemberTypeDescription
alloc_cblv_cache_alloc_cb_tThe allocation function for cache entries
init_cblv_cache_init_cb_tThe initialization function for cache entries
destroy_cblv_cache_destroy_cb_tThe destruction function for cache entries
get_cblv_cache_get_cb_tThe get function for cache entries
add_cblv_cache_add_cb_tThe add function for cache entries
remove_cblv_cache_remove_cb_tThe remove function for cache entries
drop_cblv_cache_drop_cb_tThe drop function for cache entries
drop_all_cblv_cache_drop_all_cb_tThe drop all function for cache entries
get_victim_cblv_cache_get_victim_cbThe get victim function for cache entries
reserve_cond_cblv_cache_reserve_cond_cbThe reserve condition function for cache entries
iter_create_cblv_cache_iter_create_cbThe iterator creation function for cache entries
struct

_lv_cache_slot_size_t

Cache entry slot struct

To add new fields to the cache entry, add them to a new struct and add it to the first field of the cache data struct. And this one is a size slot for the cache entry.

MemberTypeDescription
sizesize_t

Typedefs

lv_cache_entry_t

 
typedef struct _lv_cache_entry_t lv_cache_entry_t
Used by 20 functions
  • lv_vg_lite_stroke_get_path — param cache_entry
  • lv_vg_lite_stroke_drop — param cache_entry
  • lv_cache_release — param entry
  • lv_cache_entry_get_cache — param entry
  • lv_cache_entry_init — param entry
  • lv_cache_entry_delete — param entry
  • lv_cache_entry_get_ref — param entry
  • lv_cache_entry_get_node_size — param entry
  • lv_cache_entry_is_invalid — param entry
  • lv_cache_entry_get_data — param entry
  • lv_cache_entry_reset_ref — param entry
  • lv_cache_entry_inc_ref — param entry
  • lv_cache_entry_dec_ref — param entry
  • lv_cache_entry_set_node_size — param entry
  • lv_cache_entry_set_cache — param entry
  • lv_cache_entry_acquire_data — param entry
  • lv_cache_entry_release_data — param entry
  • lv_cache_entry_set_flag — param entry
  • lv_cache_entry_remove_flag — param entry
  • lv_cache_entry_has_flag — param entry

lv_cache_t

 
typedef struct _lv_cache_t lv_cache_t
Used by 23 functions
  • lv_cache_destroy — param cache
  • lv_cache_acquire — param cache
  • lv_cache_acquire_or_create — param cache
  • lv_cache_add — param cache
  • lv_cache_release — param cache
  • lv_cache_reserve — param cache
  • lv_cache_drop — param cache
  • lv_cache_drop_all — param cache
  • lv_cache_evict_one — param cache
  • lv_cache_set_max_size — param cache
  • lv_cache_get_max_size — param cache
  • lv_cache_get_size — param cache
  • lv_cache_get_free_size — param cache
  • lv_cache_is_enabled — param cache
  • lv_cache_set_compare_cb — param cache
  • lv_cache_set_create_cb — param cache
  • lv_cache_set_free_cb — param cache
  • lv_cache_set_name — param cache
  • lv_cache_get_name — param cache
  • lv_cache_iter_create — param cache
  • lv_cache_entry_alloc — param cache
  • lv_cache_entry_init — param cache
  • lv_cache_entry_set_cache — param cache

lv_cache_ops_t

 
typedef struct _lv_cache_ops_t lv_cache_ops_t
Used by 1 function
  • lv_cache_create — param ops

lv_cache_class_t

 
typedef struct _lv_cache_class_t lv_cache_class_t
Used by 1 function
  • lv_cache_create — param cache_class

lv_cache_compare_res_t

 
typedef int32_t lv_cache_compare_res_t

lv_cache_create_cb_t

 
typedef bool(* lv_cache_create_cb_t) (void *node, void *user_data)
Used by 1 function
  • lv_cache_set_create_cb — param alloc_cb

lv_cache_free_cb_t

 
typedef void(* lv_cache_free_cb_t) (void *node, void *user_data)
Used by 1 function
  • lv_cache_set_free_cb — param free_cb

lv_cache_compare_cb_t

 
typedef lv_cache_compare_res_t(* lv_cache_compare_cb_t) (const void *a, const void *b)
Used by 1 function
  • lv_cache_set_compare_cb — param compare_cb

lv_cache_alloc_cb_t

 
typedef void *(* lv_cache_alloc_cb_t) (void)

The cache instance allocation function, used by the cache class to allocate memory for cache instances.

lv_cache_init_cb_t

 
typedef bool(* lv_cache_init_cb_t) (lv_cache_t *cache)

The cache instance initialization function, used by the cache class to initialize the cache instance.

lv_cache_destroy_cb_t

 
typedef void(* lv_cache_destroy_cb_t) (lv_cache_t *cache, void *user_data)

The cache instance destruction function, used by the cache class to destroy the cache instance.

lv_cache_get_cb_t

 
typedef lv_cache_entry_t *(* lv_cache_get_cb_t) (lv_cache_t *cache, const void *key, void *user_data)

The cache get function, used by the cache class to get a cache entry by its key.

lv_cache_add_cb_t

 
typedef lv_cache_entry_t *(* lv_cache_add_cb_t) (lv_cache_t *cache, const void *key, void *user_data)

The cache add function, used by the cache class to add a cache entry with a given key. This function only cares about how to add the entry, it doesn't check if the entry already exists and doesn't care about is it a victim or not.

lv_cache_remove_cb_t

 
typedef void(* lv_cache_remove_cb_t) (lv_cache_t *cache, lv_cache_entry_t *entry, void *user_data)

The cache remove function, used by the cache class to remove a cache entry from the cache but doesn't free the memory.. This function only cares about how to remove the entry, it doesn't care about is it a victim or not.

lv_cache_drop_cb_t

 
typedef void(* lv_cache_drop_cb_t) (lv_cache_t *cache, const void *key, void *user_data)

The cache drop function, used by the cache class to remove a cache entry from the cache and free the memory.

lv_cache_drop_all_cb_t

 
typedef void(* lv_cache_drop_all_cb_t) (lv_cache_t *cache, void *user_data)

The cache drop all function, used by the cache class to remove all cache entries from the cache and free the memory.

lv_cache_get_victim_cb

 
typedef lv_cache_entry_t *(* lv_cache_get_victim_cb) (lv_cache_t *cache, void *user_data)

The cache get victim function, used by the cache class to get a victim entry to be evicted.

lv_cache_reserve_cond_cb

 
typedef lv_cache_reserve_cond_res_t(* lv_cache_reserve_cond_cb) (lv_cache_t *cache, const void *key, size_t size, void *user_data)

The cache reserve condition function, used by the cache class to check if a new entry can be added to the cache without exceeding its maximum size. See lv_cache_reserve_cond_res_t for the possible results.

lv_cache_iter_create_cb

 
typedef lv_iter_t *(* lv_cache_iter_create_cb) (lv_cache_t *cache)

The cache iterator creation function, used by the cache class to create an iterator for the cache.

lv_cache_slot_size_t

 
typedef struct _lv_cache_slot_size_t lv_cache_slot_size_t

Dependencies

Last updated on

On this page