/* retoor <retoor@molodetz.nl> */
#ifndef FUSEDAV_CACHE_H
#define FUSEDAV_CACHE_H
#include <pthread.h>
#include <stdint.h>
#include <sys/stat.h>
#include <time.h>
typedef struct cache_entry {
char *key;
void *value;
size_t value_size;
time_t created_at;
int ttl_ms;
struct cache_entry *next;
} cache_entry_t;
typedef struct {
cache_entry_t *head;
int max_entries;
int current_entries;
int default_ttl_ms;
pthread_mutex_t lock;
} cache_t;
typedef struct {
char *name;
int is_directory;
off_t size;
time_t mtime;
} dir_entry_t;
typedef struct {
dir_entry_t *entries;
int count;
} dir_listing_t;
cache_t *cache_init(int max_entries, int default_ttl_ms);
void cache_destroy(cache_t *cache);
int cache_get_stat(cache_t *cache, const char *key, struct stat *st);
int cache_put_stat(cache_t *cache, const char *key, const struct stat *st);
int cache_get_dir(cache_t *cache, const char *key, dir_listing_t **listing);
int cache_put_dir(cache_t *cache, const char *key, const dir_listing_t *listing);
void cache_invalidate(cache_t *cache, const char *key);
void cache_invalidate_prefix(cache_t *cache, const char *prefix);
void cache_clear(cache_t *cache);
void dir_listing_free(dir_listing_t *listing);
#endif