Camel.DataCache
Description: Reference for Camel.DataCache

### 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.

#### Hierarchy

#### Ancestors

- GObject

#### Constructors

###### camel_data_cache_new

Create a new data cache.

#### 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_clear

Clear cache’s content in `path`.

since: 3.2

###### 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.

###### camel_data_cache_get_expire_enabled

Gets whether expire of cache data is enabled.

since: 3.24

###### camel_data_cache_get_filename

Lookup the filename for an item in the cache.

since: 2.26

###### camel_data_cache_get_path

Returns the path to the data cache.

since: 2.32

###### camel_data_cache_remove

Remove/expire a cache item.

###### camel_data_cache_set_expire_access

Set the cache expiration policy for access times.

###### camel_data_cache_set_expire_age

Set the cache expiration policy for aged entries.

###### camel_data_cache_set_expire_enabled

Sets whether expire of cache data is enabled.

since: 3.24

###### camel_data_cache_set_path

Sets the path to the data cache.

since: 2.32

##### Methods inherited from GObject (43)

Please see GObject for a full list of methods.

#### Properties

###### Camel.DataCache:expire-enabled

Expire Enabled.

###### Camel.DataCache:path

Path.

#### 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.

#### Class structure

    struct CamelDataCacheClass {
      GObjectClass parent_class;
      gpointer reserved;

    }

No description available.

###### Class members

`parent_class: GObjectClass`

  No description available.

`reserved: gpointer`

  No description available.