| 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>
|
|---|
| 16 | General cache (gencache) was designed to combine various kinds of caching
|
|---|
| 17 | mechanisms into one, defined by a simple API. This way, anyone can use it
|
|---|
| 18 | to create their own caching layer on top of gencache. An example of
|
|---|
| 19 | such approach is the netbios name cache.
|
|---|
| 20 | </para>
|
|---|
| 21 | </sect1>
|
|---|
| 22 |
|
|---|
| 23 | <sect1>
|
|---|
| 24 | <title>The mechanism</title>
|
|---|
| 25 | <para>
|
|---|
| 26 | Gencache utilises <emphasise>tdb</emphasise> database, like many other
|
|---|
| 27 | parts of Samba. As its origins are in Berkeley DB implementation, it
|
|---|
| 28 | uses key/value pairs stored in binary file. The values gencache
|
|---|
| 29 | operates on are string-based, however. This makes very easy to use it
|
|---|
| 30 | in command line environment eg. to quickly take a look at what's in
|
|---|
| 31 | the cache or set some value.
|
|---|
| 32 | </para>
|
|---|
| 33 |
|
|---|
| 34 | <para>
|
|---|
| 35 | All the data is stored in <filename>gencache.tdb</filename>
|
|---|
| 36 | file. Records put there are in key/value format as mentioned below,
|
|---|
| 37 | but as it's a cache, the timeout plays also important role and has a
|
|---|
| 38 | special 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>
|
|---|
| 46 | The record stored in <filename>gencache.tdb</filename> file consists
|
|---|
| 47 | of the key, the value and the expiration timeout. While the first part
|
|---|
| 48 | is stored completely independent from the others, the last two are
|
|---|
| 49 | kept together. The form the record has is:
|
|---|
| 50 | </para>
|
|---|
| 51 |
|
|---|
| 52 | <para><programlisting>
|
|---|
| 53 | key: <string>
|
|---|
| 54 | value: <12-digit timeout>/<string>
|
|---|
| 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
|
|---|
| 59 | expires. Obviously the API, the programmer is provided with, hides this detail,
|
|---|
| 60 | so that you don't have to care about checking it. Simply watch
|
|---|
| 61 | carefully the return status of the function.
|
|---|
| 62 | </para>
|
|---|
| 63 | </sect1>
|
|---|
| 64 |
|
|---|
| 65 | <sect1>
|
|---|
| 66 | <title>The API</title>
|
|---|
| 67 |
|
|---|
| 68 | <para><programlisting>
|
|---|
| 69 | BOOL gencache_init()
|
|---|
| 70 | </programlisting></para>
|
|---|
|
|---|