From 8c9b0194063411882d3bbcec80d5e5c861d37544 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Wed, 24 Jul 2024 18:54:07 +0000 Subject: Add stuff to shibari-cache Signed-off-by: Laurent Bercot --- src/cache/cache.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src/cache/cache.c') diff --git a/src/cache/cache.c b/src/cache/cache.c index 8c820fb..186450c 100644 --- a/src/cache/cache.c +++ b/src/cache/cache.c @@ -1,6 +1,36 @@ /* ISC license. */ +#include +#include +#include + #include #include "shibari-cache-internal.h" -dcache_t cache = DCACHE_ZERO ; +static dcache_t cache = DCACHE_ZERO ; + +void cache_init (uint64_t cachesize) +{ + dcache_init(&cache, cachesize) ; +} + +void cache_dump (void) +{ + if (g->dumpfile) + { + if (!dcache_save(&cache, g->dumpfile)) + { + strerr_warnwu2sys("save cache contents to ", g->dumpfile) ; + unlink_void(file) ; + } + } +} + +void cache_load (void) +{ + if (g->dumpfile) + { + if (!dcache_load(&cache, g->dumpfile)) + strerr_warnwu2sys("load cache contents from ", g->dumpfile) ; + } +} -- cgit v1.3.1