Caching

<refentry> <refmeta> <refentrytitle>SoupCache</refentrytitle> <manvolnum>3</manvolnum> <refmiscinfo>LIBSOUP-3.0 Library</refmiscinfo> </refmeta>

<refentrytitle>SoupCache</refentrytitle>

<refname>SoupCache</refname> <refpurpose>Caching support</refpurpose>

<refsect1> <title>Functions</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><returnvalue>SoupCache</returnvalue> * </entry><entry>soup_cache_new <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_cache_flush <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_cache_clear <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_cache_dump <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_cache_load <phrase>()</phrase></entry></row> <row><entry><returnvalue>guint</returnvalue> </entry><entry>soup_cache_get_max_size <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_cache_set_max_size <phrase>()</phrase></entry></row> </tbody> </tgroup> </informaltable> </refsect1> <refsect1> <title>Properties</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><type>char</type> *</entry><entry>cache-dir</entry><entry>Read / Write / Construct Only</entry></row> <row><entry><type>SoupCacheType</type></entry><entry>cache-type</entry><entry>Read / Write / Construct Only</entry></row> </tbody> </tgroup> </informaltable> </refsect1> <refsect1> <title>Types and Values</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <tbody> <row><entry></entry><entry>SoupCache</entry></row> <row><entry>enum</entry><entry>SoupCacheType</entry></row> </tbody> </tgroup> </informaltable> </refsect1> <refsect1> <title>Object Hierarchy</title> <screen> GObject <phrase>╰──</phrase> SoupCache </screen> </refsect1> <refsect1> <title>Implemented Interfaces</title> <para> SoupCache implements SoupSessionFeature and SoupContentProcessor.</para> </refsect1> <refsect1><title>Includes</title><synopsis>#include <libsoup/soup.h> </synopsis></refsect1> <refsect1> <title>Description</title> <para><type>SoupCache</type> implements a file-based cache for HTTP resources.</para> </refsect1> <refsect1> <title>Functions</title> <refsect2> <title>soup_cache_new ()</title> <programlisting><returnvalue>SoupCache</returnvalue> * soup_cache_new (<parameter>const <type>char</type> *cache_dir</parameter>, <parameter><type>SoupCacheType</type> cache_type</parameter>);</programlisting> <para>Creates a new <type>SoupCache</type>.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>cache_dir</para></entry> <entry><para>the directory to store the cached data, or <literal>NULL</literal> to use the default one. Note that since the cache isn't safe to access for multiple processes at once, and the default directory isn't namespaced by process, clients are strongly discouraged from passing <literal>NULL</literal>. </para></entry> <entry><emphasis>[nullable]</emphasis></entry></row> <row><entry><para>cache_type</para></entry> <entry><para>the <type>SoupCacheType</type> of the cache</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> a new <type>SoupCache</type></para> </refsect3></refsect2>
<refsect2> <title>soup_cache_flush ()</title> <programlisting><returnvalue>void</returnvalue> soup_cache_flush (<parameter><type>SoupCache</type> *cache</parameter>);</programlisting> <para>This function will force all pending writes in the <parameter>cache</parameter> to be committed to disk. For doing so it will iterate the <type>GMainContext</type> associated with <parameter>cache</parameter> 's session as long as needed.</para> <para>Contrast with <function>soup_cache_dump()</function>, which writes out the cache index file.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>cache</para></entry> <entry><para>a <type>SoupCache</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_cache_clear ()</title> <programlisting><returnvalue>void</returnvalue> soup_cache_clear (<parameter><type>SoupCache</type> *cache</parameter>);</programlisting> <para>Will remove all entries in the <parameter>cache</parameter> plus all the cache files.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>cache</para></entry> <entry><para>a <type>SoupCache</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_cache_dump ()</title> <programlisting><returnvalue>void</returnvalue> soup_cache_dump (<parameter><type>SoupCache</type> *cache</parameter>);</programlisting> <para>Synchronously writes the cache index out to disk. Contrast with <function>soup_cache_flush()</function>, which writes pending cache <emphasis>entries</emphasis> to disk.</para> <para>You must call this before exiting if you want your cache data to persist between sessions.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>cache</para></entry> <entry><para>a <type>SoupCache</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_cache_load ()</title> <programlisting><returnvalue>void</returnvalue> soup_cache_load (<parameter><type>SoupCache</type> *cache</parameter>);</programlisting> <para>Loads the contents of <parameter>cache</parameter> 's index into memory.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>cache</para></entry> <entry><para>a <type>SoupCache</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_cache_get_max_size ()</title> <programlisting><returnvalue>guint</returnvalue> soup_cache_get_max_size (<parameter><type>SoupCache</type> *cache</parameter>);</programlisting> <para>Gets the maximum size of the cache.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>cache</para></entry> <entry><para>a <type>SoupCache</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> the maximum size of the cache, in bytes.</para> </refsect3></refsect2>
<refsect2> <title>soup_cache_set_max_size ()</title> <programlisting><returnvalue>void</returnvalue> soup_cache_set_max_size (<parameter><type>SoupCache</type> *cache</parameter>, <parameter><type>guint</type> max_size</parameter>);</programlisting> <para>Sets the maximum size of the cache.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>cache</para></entry> <entry><para>a <type>SoupCache</type></para></entry> <entry></entry></row> <row><entry><para>max_size</para></entry> <entry><para>the maximum size of the cache, in bytes</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2> </refsect1>
<refsect1> <title>Types and Values</title> <refsect2> <title>SoupCache</title> <programlisting>typedef struct _SoupCache SoupCache;</programlisting> <para>Class implementing caching for HTTP resources.</para> </refsect2>
<refsect2> <title>enum SoupCacheType</title> <para>The type of cache; this affects what kinds of responses will be saved.</para> <refsect3> <title>Members</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>SOUP_CACHE_SINGLE_USER</para></entry> <entry><para>a single-user cache</para> </entry> <entry></entry> </row> <row><entry><para>SOUP_CACHE_SHARED</para></entry> <entry><para>a shared cache</para> </entry> <entry></entry> </row> </tbody></tgroup></informaltable> </refsect3></refsect2> </refsect1>
<refsect1> <title>Property Details</title> <refsect2><title>The <literal>“cache-dir”</literal> property</title> <programlisting> “cache-dir” <type>char</type> *</programlisting> <para>The directory to store the cache files.</para><para>Owner: SoupCache</para> <para>Flags: Read / Write / Construct Only</para> <para>Default value: NULL</para> </refsect2>
<refsect2><title>The <literal>“cache-type”</literal> property</title> <programlisting> “cache-type” <type>SoupCacheType</type></programlisting> <para>Whether the cache is private or shared.</para><para>Owner: SoupCache</para> <para>Flags: Read / Write / Construct Only</para> <para>Default value: SOUP_CACHE_SINGLE_USER</para> </refsect2> </refsect1>
</refentry>