-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcache.c
More file actions
52 lines (43 loc) · 962 Bytes
/
Copy pathcache.c
File metadata and controls
52 lines (43 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdlib.h>
#include "chunk.h"
#include "cache.h"
chunk_cache *cache_new()
{
chunk_cache *new;
new = malloc(sizeof(chunk_cache));
if (new != NULL)
{
new->data = NULL;
new->free = NULL;
new->set = NULL;
new->get = NULL;
new->empty = NULL;
}
return new;
}
void cache_free(chunk_cache *doomed)
{
if (doomed != NULL)
{
if (doomed->free != NULL)
doomed->free(doomed);
free(doomed);
}
}
int cache_set(chunk_cache *cache, int64_t key, chunk *payload)
{
if (cache == NULL || cache->set == NULL)
return -1;
return cache->set(cache, key, payload);
}
int cache_get(chunk_cache *cache, int64_t key, chunk **out)
{
if (cache == NULL || cache->get == NULL)
return -1;
return cache->get(cache, key, out);
}
void cache_empty(chunk_cache *cache)
{
if (cache != NULL && cache->empty != NULL)
cache->empty(cache);
}