Blame


1 6bef87be 2018-09-11 stsp /*
2 6bef87be 2018-09-11 stsp * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
3 6bef87be 2018-09-11 stsp *
4 6bef87be 2018-09-11 stsp * Permission to use, copy, modify, and distribute this software for any
5 6bef87be 2018-09-11 stsp * purpose with or without fee is hereby granted, provided that the above
6 6bef87be 2018-09-11 stsp * copyright notice and this permission notice appear in all copies.
7 6bef87be 2018-09-11 stsp *
8 6bef87be 2018-09-11 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 6bef87be 2018-09-11 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 6bef87be 2018-09-11 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 6bef87be 2018-09-11 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 6bef87be 2018-09-11 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 6bef87be 2018-09-11 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 6bef87be 2018-09-11 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 6bef87be 2018-09-11 stsp */
16 6bef87be 2018-09-11 stsp
17 6bef87be 2018-09-11 stsp enum got_object_cache_type {
18 6bef87be 2018-09-11 stsp GOT_OBJECT_CACHE_TYPE_OBJ,
19 6bef87be 2018-09-11 stsp GOT_OBJECT_CACHE_TYPE_TREE,
20 6bef87be 2018-09-11 stsp GOT_OBJECT_CACHE_TYPE_COMMIT,
21 6bef87be 2018-09-11 stsp };
22 6bef87be 2018-09-11 stsp
23 6bef87be 2018-09-11 stsp struct got_object_cache_entry {
24 6bef87be 2018-09-11 stsp struct got_object_id id;
25 6bef87be 2018-09-11 stsp union {
26 6bef87be 2018-09-11 stsp struct got_object *obj;
27 6bef87be 2018-09-11 stsp struct got_tree_object *tree;
28 6bef87be 2018-09-11 stsp struct got_commit_object *commit;
29 6bef87be 2018-09-11 stsp } data;
30 6bef87be 2018-09-11 stsp };
31 6bef87be 2018-09-11 stsp
32 6bef87be 2018-09-11 stsp struct got_object_cache {
33 6bef87be 2018-09-11 stsp enum got_object_cache_type type;
34 6bef87be 2018-09-11 stsp struct got_object_idcache *idcache;
35 6bef87be 2018-09-11 stsp size_t size;
36 221e79cd 2018-09-16 stsp int cache_searches;
37 6bef87be 2018-09-11 stsp int cache_hit;
38 6bef87be 2018-09-11 stsp int cache_miss;
39 315fa2b2 2018-09-15 stsp int cache_evict;
40 6bef87be 2018-09-11 stsp };
41 6bef87be 2018-09-11 stsp
42 6bef87be 2018-09-11 stsp const struct got_error *got_object_cache_init(struct got_object_cache *,
43 6bef87be 2018-09-11 stsp enum got_object_cache_type);
44 6bef87be 2018-09-11 stsp const struct got_error *got_object_cache_add(struct got_object_cache *,
45 6bef87be 2018-09-11 stsp struct got_object_id *, void *);
46 6bef87be 2018-09-11 stsp void *got_object_cache_get(struct got_object_cache *, struct got_object_id *);
47 6bef87be 2018-09-11 stsp void got_object_cache_close(struct got_object_cache *);