BRL-CAD
cache.h
Go to the documentation of this file.
1 /* C A C H E . H
2  * BRL-CAD
3  *
4  * Copyright (c) 2018-2024 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @file cache.h
21  *
22  * Routines for managing and accessing a key/value data store.
23  *
24  */
25 
26 #ifndef BU_CACHE_H
27 #define BU_CACHE_H 1
28 
29 #include "common.h"
30 
31 #include "bu/defines.h"
32 
33 __BEGIN_DECLS
34 
35 struct bu_cache_impl;
36 
37 struct bu_cache {
38  struct bu_cache_impl *i;
39 };
40 
41 /**
42  * Opens the specified cache database from the BRL-CAD BU_DIR_CACHE folder.
43  * The cache_db string may contain a hierarchical path, but note that all
44  * paths will be interpreted as relative to the BU_DIR_CACHE location - no
45  * absolute paths can be specified.
46  *
47  * If the create flag is non-zero, bu_cache_open will create the specified
48  * cache_db if it does not already exist.
49  *
50  * returns the bu_cache structure on success, NULL on failure.
51  */
52 BU_EXPORT extern struct bu_cache *bu_cache_open(const char *cache_db, int create);
53 
54 /**
55  * Closes the bu_cache and frees all associated memory.
56  */
57 BU_EXPORT extern void bu_cache_close(struct bu_cache *c);
58 
59 /**
60  * Erase the specified cache from disk. Any open instances of the
61  * cache should be closed before calling this function.
62  */
63 BU_EXPORT void bu_cache_erase(const char *cache_db);
64 
65 /**
66  * Retrieve data (read-only) from the cache using the specified key. User
67  * should call bu_cache_get_done once their use of data is complete.
68  *
69  * Returns the size of the retrieved data.
70  */
71 BU_EXPORT size_t bu_cache_get(void **data, const char *key, struct bu_cache *c);
72 
73 /**
74  * Data retrieved using bu_cache_get is temporary - once the user is done
75  * either reading it or copying it, libbu needs to be told that the usage of
76  * the returned data is complete. */
77 BU_EXPORT void bu_cache_get_done(const char *key, struct bu_cache *c);
78 
79 /**
80  * Assign data to the cache using the specified key
81  */
82 BU_EXPORT size_t bu_cache_write(void **data, const char *key, struct bu_cache *c);
83 
84 /**
85  * Clear data associated with the specified key from the cache
86  */
87 BU_EXPORT void bu_cache_clear(const char *key, struct bu_cache *c);
88 
89 
90 __END_DECLS
91 
92 #endif /* BU_CACHE_H */
93 
94 /*
95  * Local Variables:
96  * tab-width: 8
97  * mode: C
98  * indent-tabs-mode: t
99  * c-file-style: "stroustrup"
100  * End:
101  * ex: shiftwidth=4 tabstop=8
102  */
void bu_cache_clear(const char *key, struct bu_cache *c)
size_t bu_cache_write(void **data, const char *key, struct bu_cache *c)
struct bu_cache * bu_cache_open(const char *cache_db, int create)
void bu_cache_close(struct bu_cache *c)
void bu_cache_get_done(const char *key, struct bu_cache *c)
size_t bu_cache_get(void **data, const char *key, struct bu_cache *c)
void bu_cache_erase(const char *cache_db)
Header file for the BRL-CAD common definitions.
void int * c
Definition: tig.h:139
Definition: cache.h:37
struct bu_cache_impl * i
Definition: cache.h:38