forked from bloominstituteoftechnology/C-Web-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache.h
29 lines (24 loc) · 947 Bytes
/
cache.h
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
#ifndef _WEBCACHE_H_
#define _WEBCACHE_H_
// Individual hash table entry
struct cache_entry {
char *path; // Endpoint path--key to the cache
char *content_type;
int content_length;
void *content;
struct cache_entry *prev, *next; // Doubly-linked list
};
// A cache
struct cache {
struct hashtable *index;
struct cache_entry *head, *tail; // Doubly-linked list
int max_size; // Maxiumum number of entries
int cur_size; // Current number of entries
};
extern struct cache_entry *alloc_entry(char *path, char *content_type, void *content, int content_length);
extern void free_entry(struct cache_entry *entry);
extern struct cache *cache_create(int max_size, int hashsize);
extern void cache_free(struct cache *cache);
extern void cache_put(struct cache *cache, char *path, char *content_type, void *content, int content_length);
extern struct cache_entry *cache_get(struct cache *cache, char *path);
#endif