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 f4a881ce 2018-11-17 stsp GOT_OBJECT_CACHE_TYPE_TAG,
22 d3c116bf 2021-10-15 stsp GOT_OBJECT_CACHE_TYPE_RAW,
23 6bef87be 2018-09-11 stsp };
24 6bef87be 2018-09-11 stsp
25 6bef87be 2018-09-11 stsp struct got_object_cache_entry {
26 6bef87be 2018-09-11 stsp struct got_object_id id;
27 6bef87be 2018-09-11 stsp union {
28 6bef87be 2018-09-11 stsp struct got_object *obj;
29 6bef87be 2018-09-11 stsp struct got_tree_object *tree;
30 6bef87be 2018-09-11 stsp struct got_commit_object *commit;
31 f4a881ce 2018-11-17 stsp struct got_tag_object *tag;
32 d3c116bf 2021-10-15 stsp struct got_raw_object *raw;
33 6bef87be 2018-09-11 stsp } data;
34 6bef87be 2018-09-11 stsp };
35 6bef87be 2018-09-11 stsp
36 6bef87be 2018-09-11 stsp struct got_object_cache {
37 6bef87be 2018-09-11 stsp enum got_object_cache_type type;
38 f054b67a 2018-11-05 stsp struct got_object_idset *idset;
39 6bef87be 2018-09-11 stsp size_t size;
40 221e79cd 2018-09-16 stsp int cache_searches;
41 6bef87be 2018-09-11 stsp int cache_hit;
42 6bef87be 2018-09-11 stsp int cache_miss;
43 315fa2b2 2018-09-15 stsp int cache_evict;
44 01cd7614 2019-05-22 stsp int cache_toolarge;
45 97725928 2022-08-30 stsp size_t max_cached_size;
46 6bef87be 2018-09-11 stsp };
47 6bef87be 2018-09-11 stsp
48 6bef87be 2018-09-11 stsp const struct got_error *got_object_cache_init(struct got_object_cache *,
49 6bef87be 2018-09-11 stsp enum got_object_cache_type);
50 6bef87be 2018-09-11 stsp const struct got_error *got_object_cache_add(struct got_object_cache *,
51 6bef87be 2018-09-11 stsp struct got_object_id *, void *);
52 6bef87be 2018-09-11 stsp void *got_object_cache_get(struct got_object_cache *, struct got_object_id *);
53 6bef87be 2018-09-11 stsp void got_object_cache_close(struct got_object_cache *);