source: vendor/3.6.23/docs-xml/Samba3-Developers-Guide/gencache.xml

Last change on this file was 414, checked in by Herwig Bauernfeind, 15 years ago

Samba 3.5.0: Initial import

File size: 3.9 KB
Line 
1<?xml version="1.0" encoding="iso-8859-1"?>
2<!DOCTYPE chapter PUBLIC "-//Samba-Team//DTD DocBook V4.2-Based Variant V1.0//EN" "http://www.samba.org/samba/DTD/samba-doc">
3<chapter id="gencache">
4<chapterinfo>
5 <author>
6 <firstname>Rafal</firstname><surname>Szczesniak</surname>
7 </author>
8 <pubdate>April 2003</pubdate>
9</chapterinfo>
10
11<title>General cache mechanism and API</title>
12
13<sect1>
14<title>Abstract</title>
15<para>
16General cache (gencache) was designed to combine various kinds of caching
17mechanisms into one, defined by a simple API. This way, anyone can use it
18to create their own caching layer on top of gencache. An example of
19such approach is the netbios name cache.
20</para>
21</sect1>
22
23<sect1>
24<title>The mechanism</title>
25<para>
26Gencache utilises <emphasise>tdb</emphasise> database, like many other
27parts of Samba. As its origins are in Berkeley DB implementation, it
28uses key/value pairs stored in binary file. The values gencache
29operates on are string-based, however. This makes very easy to use it
30in command line environment eg. to quickly take a look at what's in
31the cache or set some value.
32</para>
33
34<para>
35All the data is stored in <filename>gencache.tdb</filename>
36file. Records put there are in key/value format as mentioned below,
37but as it's a cache, the timeout plays also important role and has a
38special place in the key/value pair, as well as API.
39</para>
40</sect1>
41
42
43<sect1>
44<title>The data structure</title>
45<para>
46The record stored in <filename>gencache.tdb</filename> file consists
47of the key, the value and the expiration timeout. While the first part
48is stored completely independent from the others, the last two are
49kept together. The form the record has is:
50</para>
51
52<para><programlisting>
53key: &lt;string&gt;
54value: &lt;12-digit timeout&gt;/&lt;string&gt;
55</programlisting></para>
56
57<para>The timeout part is the ASCII representation of
58<emphasis>time_t</emphasis> value of the time when the cache entry
59expires. Obviously the API, the programmer is provided with, hides this detail,
60so that you don't have to care about checking it. Simply watch
61carefully the return status of the function.
62</para>
63</sect1>
64
65<sect1>
66<title>The API</title>
67
68<para><programlisting>
69BOOL gencache_init()
70</programlisting></para>
71
72<para>This is used to initialise to whole caching mechanism. It means
73opening the file or creating it if non-existing. If it's already been
74opened earlier, then the routine just does nothing and returns
75<constant>true</constant>. If something goes wrong, say the user
76doesn't have necessary rights, the function returns
77<constant>false</constant>.</para>
78
79<para><programlisting>
80BOOL gencache_shutdown()
81</programlisting></para>
82
83<para>This is the proper way to close the cache file. It simply
84returns <constant>true</constant> after successful closing file and
85<constant>false</constant> upon a failure.</para>
86
87<para><programlisting>
88BOOL gencache_set(const char* keystr, const char* value, time_t timeout)
89</programlisting></para>
90
91<para>This is one of the most basic functions. What it allows you to
92do is to set some particular cache entry. If the entry haven't
93existed yet, the function will act just as it was "gencache_add"
94function. If it's already been in the cache, the entry will be set to
95the new value. In either case, the cache entry will be set with given
96key, value and timeout. Thus it is comfortable way to just set the
97entry and not care about the details.</para>
98
99<para><programlisting>
100BOOL gencache_set_only(const char* keystr, const char* value, time_t timeout)
101</programlisting></para>
102
103<para><programlisting>
104BOOL gencache_del(const char* keystr)
105</programlisting></para>
106
107<para><programlisting>
108BOOL gencache_get(const char* keystr, char** valstr, time_t* timeout)
109</programlisting></para>
110
111<para><programlisting>
112void gencache_iterate(void (*fn)(const char* key, const char *value, time_t timeout, void* dptr),
113 void* data, const char* keystr_pattern)
114
115</programlisting></para>
116
117</sect1>
118
119</chapter>
Note: See TracBrowser for help on using the repository browser.