Class
CamelDataCache
Description [src]
class Camel.DataCache : GObject.Object
{
CamelDataCachePrivate* priv
}
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));
}
camel_data_cache_add_atomic() writes to a temporary file in the same
directory as the target, so camel_data_cache_commit_atomic() can rename
it into place atomically. Any concurrent camel_data_cache_get() call for
the same item blocks until the write is either committed or discarded.
Instance methods
camel_data_cache_add_atomic
Open a temporary file for writing a new cache item identified by path
and key. The temporary file lives in the same directory as the final
target so that camel_data_cache_commit_atomic() can rename it into place
atomically (same-filesystem rename).
unstable since: 3.62
camel_data_cache_commit_atomic
Finalise an atomic cache write. stream is closed and unreffed, the
temporary file is renamed to its final location, and a new GIOStream
opened on the committed file is returned (equivalent to calling
camel_data_cache_get() after a successful write).
unstable since: 3.62
camel_data_cache_discard_atomic
Discard an atomic cache write. stream is closed and unreffed, the
temporary file is removed, and the bag reservation is released so that
other threads can retry the operation.
unstable since: 3.62
camel_data_cache_foreach_remove
Traverses the cdc sub-cache identified by path and calls func for each found file.
If the func returns TRUE, then the file is removed, if FALSE, it’s kept in the cache.
since: 3.26
camel_data_cache_get
Lookup an item in the cache. If the item exists, a GIOStream is returned
for the item. The stream may be shared by multiple callers, so ensure the
stream is in a valid state through external locking.
Signals
Signals inherited from GObject (1)
GObject::notify
The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.