1 #ifndef __LIB_GENCACHE_GENCACHE_H__
2 #define __LIB_GENCACHE_GENCACHE_H__
5 * Cache initialisation function. Opens cache tdb file or creates
6 * it if does not exist.
8 * @return true on successful initialisation of the cache or
11 bool gencache_init(struct loadparm_context *lp_ctx);
14 * Cache shutdown function. Closes opened cache tdb file.
16 * @return true on successful closing the cache or
17 * false on failure during cache shutdown
19 bool gencache_shutdown(void);
22 * Set an entry in the cache file. If there's no such
25 * @param keystr string that represents a key of this entry
26 * @param value text representation value being cached
27 * @param timeout time when the value is expired
29 * @retval true when entry is successfuly stored
30 * @retval false on failure
32 bool gencache_set(const char *keystr, const char *value, time_t timeout);
35 * Set existing entry to the cache file.
37 * @param keystr string that represents a key of this entry
38 * @param valstr text representation value being cached
39 * @param timeout time when the value is expired
41 * @retval true when entry is successfuly set
42 * @retval false on failure
44 bool gencache_set_only(const char *keystr, const char *valstr, time_t timeout);
47 * Delete one entry from the cache file.
49 * @param keystr string that represents a key of this entry
51 * @retval true upon successful deletion
52 * @retval false in case of failure
54 bool gencache_del(const char *keystr);
57 * Get existing entry from the cache file.
59 * @param keystr string that represents a key of this entry
60 * @param valstr buffer that is allocated and filled with the entry value
61 * buffer's disposing must be done outside
62 * @param timeout pointer to a time_t that is filled with entry's
65 * @retval true when entry is successfuly fetched
66 * @retval false for failure
68 bool gencache_get(const char *keystr, char **valstr, time_t *timeout);
71 * Iterate through all entries which key matches to specified pattern
73 * @param fn pointer to the function that will be supplied with each single
74 * matching cache entry (key, value and timeout) as an arguments
75 * @param data void pointer to an arbitrary data that is passed directly to the fn
76 * function on each call
77 * @param keystr_pattern pattern the existing entries' keys are matched to
80 void gencache_iterate(void (*fn)(const char* key, const char *value, time_t timeout, void* dptr),
81 void* data, const char* keystr_pattern);
83 /********************************************************************
85 ********************************************************************/
86 int gencache_lock_entry( const char *key );
88 /********************************************************************
90 ********************************************************************/
91 void gencache_unlock_entry( const char *key );
93 #endif /* __LIB_GENCACHE_GENCACHE_H__ */