DataCache


Object Hierarchy:

Object hierarchy for DataCache

Description:

[ CCode ( type_id = "camel_data_cache_get_type ()" ) ]
public class DataCache : Object

A file-based cache for arbitrary keyed data, typically used by mail providers to store downloaded message bodies.

Each item is identified by a (path, key) pair. The path selects a logical sub-cache (e.g. `"cur"` for downloaded messages, `"new"` for outgoing spool), and key is a per-item identifier such as a message UID.

To write a new item safely — so that a crash or cancellation never leaves a truncated file in the cache — use the atomic write API:

    GIOStream *stream;
gboolean success;

stream = camel_data_cache_add_atomic (cache, "cur", uid, error);
if (!stream)
goto fail;

success = write_message_to_stream (G_OUTPUT_STREAM (
g_io_stream_get_output_stream (stream)), message, error);

if (success) {
stream = camel_data_cache_commit_atomic (cache, g_steal_pointer (&stream), error);
/<!-- -->* stream is now open on the committed file, or NULL on error *<!-- -->/
} else {
camel_data_cache_discard_atomic (cache, g_steal_pointer (&stream));
}

add_atomic writes to a temporary file in the same directory as the target, so commit_atomic can rename it into place atomically. Any concurrent @get call for the same item blocks until the write is either committed or discarded.


Namespace: Camel
Package: camel-1.2

Content:

Properties:

Creation methods:

Methods:

Inherited Members: