Initialize the gmime for upstream
[platform/upstream/gmime.git] / util / cache.h
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*  GMime
3  *  Copyright (C) 2000-2012 Jeffrey Stedfast
4  *
5  *  This library is free software; you can redistribute it and/or
6  *  modify it under the terms of the GNU Lesser General Public License
7  *  as published by the Free Software Foundation; either version 2.1
8  *  of the License, or (at your option) any later version.
9  *
10  *  This library is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  *  Lesser General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Lesser General Public
16  *  License along with this library; if not, write to the Free
17  *  Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
18  *  02110-1301, USA.
19  */
20
21
22 #ifndef __CACHE_H__
23 #define __CACHE_H__
24
25 #include <glib.h>
26
27 #include <sys/types.h>
28
29 #include <util/list.h>
30
31 G_BEGIN_DECLS
32
33 typedef struct _Cache Cache;
34
35 typedef struct {
36         ListNode node;
37         Cache *cache;
38         char *key;
39 } CacheNode;
40
41 typedef gboolean (*CacheNodeExpireFunc) (Cache *cache, CacheNode *node);
42 typedef void (*CacheNodeFreeFunc) (CacheNode *node);
43
44 struct _Cache {
45         List list;
46         size_t size;
47         size_t max_size;
48         size_t node_size;
49         GHashTable *node_hash;
50         CacheNodeExpireFunc expire;
51         CacheNodeFreeFunc free_node;
52 };
53
54
55 G_GNUC_INTERNAL Cache *cache_new (CacheNodeExpireFunc expire, CacheNodeFreeFunc free_node,
56                                   size_t bucket_size, size_t max_cache_size);
57
58 G_GNUC_INTERNAL void cache_free (Cache *cache);
59
60 G_GNUC_INTERNAL CacheNode *cache_node_insert (Cache *cache, const char *key);
61 G_GNUC_INTERNAL CacheNode *cache_node_lookup (Cache *cache, const char *key, gboolean use);
62
63 G_GNUC_INTERNAL void cache_expire_unused (Cache *cache);
64 G_GNUC_INTERNAL void cache_node_expire (CacheNode *node);
65
66 G_END_DECLS
67
68 #endif /* __CACHE_H__ */