Add a general key-value caching framework

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui
2019-05-03 16:20:47 +01:00
parent be673f93c6
commit c08fd08ea4
3 changed files with 77 additions and 1 deletions

14
src/cache.h Normal file
View File

@@ -0,0 +1,14 @@
#pragma once
struct cache;
typedef void *(*cache_getter_t)(void *user_data, const char *key);
typedef void (*cache_free_t)(void *user_data, void *data);
struct cache *new_cache(void *user_data, cache_getter_t getter, cache_free_t f);
void *cache_get(struct cache *, const char *key);
void cache_invalidate(struct cache *, const char *key);
void cache_invalidate_all(struct cache *);
/// Returns the user data passed to `new_cache`
void *cache_free(struct cache *);