## FolksAvatarCache

FolksAvatarCache — A singleton persistent cache for avatars in folks.

## Functions

void | folks_avatar_cache_load_avatar ()
GLoadableIcon * | folks_avatar_cache_load_avatar_finish ()
void | folks_avatar_cache_store_avatar ()
gchar * | folks_avatar_cache_store_avatar_finish ()
void | folks_avatar_cache_remove_avatar ()
void | folks_avatar_cache_remove_avatar_finish ()
gchar * | folks_avatar_cache_build_uri_for_avatar ()
FolksAvatarCache * | folks_avatar_cache_dup ()

## Types and Values

#define | FOLKS_TYPE_AVATAR_CACHE
struct | FolksAvatarCache
struct | FolksAvatarCacheClass

## Description

Avatars may be added to the cache, and referred to by a persistent URI from that point onwards. The avatars will be stored on disk in the user's XDG cache directory.

The avatar cache is typically used by backends where retrieving avatars is an expensive operation (for example, they have to be downloaded from the network every time they're used).

All avatars from all users of the FolksAvatarCache are stored in the same namespace, so callers must ensure that the IDs they use for avatars are globally unique (e.g. by using the corresponding "uid").

Ongoing store operations (`folks_avatar_cache_store_avatar()`) are rate limited to try and prevent file descriptor exhaustion. Load operations (`folks_avatar_cache_load_avatar()`) must be rate limited by the client, as the file I/O occurs when calling ``g_loadable_icon_load()`` rather than when retrieving the GLoadableIcon from the cache.

## Functions

### folks_avatar_cache_load_avatar ()

    void
    folks_avatar_cache_load_avatar (FolksAvatarCache *self,
                                    const gchar *id,
                                    GAsyncReadyCallback _callback_,
                                    gpointer _user_data_);

Fetch an avatar from the cache by its globally unique ID.

It is up to the caller to ensure that file I/O is rate-limited when loading many avatars in parallel, by limiting calls to ``g_loadable_icon_load()``.

GError will be returned in `error`

if checking for existence of the cache file failed

See also: `folks_avatar_cache_load_avatar_finish()`

#### Parameters

self | the FolksAvatarCache instance |
id | . the globally unique ID for the avatar . | [in]
_callback_ | callback to call when the request is satisfied. | [scope async]
_user_data_ | the data to pass to `_callback_` function. | [closure]

Since: 0.6.0

### folks_avatar_cache_load_avatar_finish ()

    GLoadableIcon *
    folks_avatar_cache_load_avatar_finish (FolksAvatarCache *self,
                                           GAsyncResult *_res_,
                                           GError **error);

Fetch an avatar from the cache by its globally unique ID.

It is up to the caller to ensure that file I/O is rate-limited when loading many avatars in parallel, by limiting calls to ``g_loadable_icon_load()``.

GError will be returned in `error`

if checking for existence of the cache file failed

See also: `folks_avatar_cache_load_avatar()`

#### Parameters

self | the FolksAvatarCache instance |
_res_ | a GAsyncResult |
error | location to store the error occurring, or `NULL` to ignore |

#### Returns

Avatar from the cache, or `null` if it doesn't exist in the cache

Since: 0.6.0

### folks_avatar_cache_store_avatar ()

    void
    folks_avatar_cache_store_avatar (FolksAvatarCache *self,
                                     const gchar *id,
                                     GLoadableIcon *avatar,
                                     GAsyncReadyCallback _callback_,
                                     gpointer _user_data_);

Store an avatar in the cache, assigning the given globally unique ID to it, which can later be used to load and remove the avatar from the cache. For example, this ID could be the UID of a persona. The URI of the cached avatar file will be returned.

This method may be called multiple times concurrently for the same avatar ID (e.g. an asynchronous call may be made, and a subsequent asynchronous call may begin before the first has finished).

Concurrent file I/O may be rate limited within each ``folks_avatar_cache_new()`` instance to avoid file descriptor exhaustion.

GError will be returned in `error`

if the avatar data couldn't be loaded, or if creating the avatar directory or cache file failed

See also: `folks_avatar_cache_store_avatar_finish()`

#### Parameters

self | the FolksAvatarCache instance |
id | . the globally unique ID for the avatar . | [in]
avatar | . the avatar data to cache . | [in]
_callback_ | callback to call when the request is satisfied. | [scope async]
_user_data_ | the data to pass to `_callback_` function. | [closure]

Since: 0.6.0

### folks_avatar_cache_store_avatar_finish ()

    gchar *
    folks_avatar_cache_store_avatar_finish
                                   (FolksAvatarCache *self,
                                    GAsyncResult *_res_,
                                    GError **error);

Store an avatar in the cache, assigning the given globally unique ID to it, which can later be used to load and remove the avatar from the cache. For example, this ID could be the UID of a persona. The URI of the cached avatar file will be returned.

This method may be called multiple times concurrently for the same avatar ID (e.g. an asynchronous call may be made, and a subsequent asynchronous call may begin before the first has finished).

Concurrent file I/O may be rate limited within each ``folks_avatar_cache_new()`` instance to avoid file descriptor exhaustion.

GError will be returned in `error`

if the avatar data couldn't be loaded, or if creating the avatar directory or cache file failed

See also: `folks_avatar_cache_store_avatar()`

#### Parameters

self | the FolksAvatarCache instance |
_res_ | a GAsyncResult |
error | location to store the error occurring, or `NULL` to ignore |

#### Returns

a URI for the file storing the cached avatar

Since: 0.6.0

### folks_avatar_cache_remove_avatar ()

    void
    folks_avatar_cache_remove_avatar (FolksAvatarCache *self,
                                      const gchar *id,
                                      GAsyncReadyCallback _callback_,
                                      gpointer _user_data_);

Remove an avatar from the cache, if it exists in the cache. If the avatar exists in the cache but there is a problem in removing it, a GError will be thrown.

GError will be returned in `error`

if deleting the cache file failed

See also: `folks_avatar_cache_remove_avatar_finish()`

#### Parameters

self | the FolksAvatarCache instance |
id | . the globally unique ID for the avatar . | [in]
_callback_ | callback to call when the request is satisfied. | [scope async]
_user_data_ | the data to pass to `_callback_` function. | [closure]

Since: 0.6.0

### folks_avatar_cache_remove_avatar_finish ()

    void
    folks_avatar_cache_remove_avatar_finish
                                   (FolksAvatarCache *self,
                                    GAsyncResult *_res_,
                                    GError **error);

Remove an avatar from the cache, if it exists in the cache. If the avatar exists in the cache but there is a problem in removing it, a GError will be thrown.

GError will be returned in `error`

if deleting the cache file failed

See also: `folks_avatar_cache_remove_avatar()`

#### Parameters

self | the FolksAvatarCache instance |
_res_ | a GAsyncResult |
error | location to store the error occurring, or `NULL` to ignore |

Since: 0.6.0

### folks_avatar_cache_build_uri_for_avatar ()

    gchar *
    folks_avatar_cache_build_uri_for_avatar
                                   (FolksAvatarCache *self,
                                    const gchar *id);

Build the URI of an avatar file in the cache from a globally unique ID. This will always succeed, even if the avatar doesn't exist in the cache.

#### Parameters

self | the FolksAvatarCache instance |
id | . the globally unique ID for the avatar . | [in]

#### Returns

URI of the avatar file with the given globally unique ID

Since: 0.6.0

### folks_avatar_cache_dup ()

    FolksAvatarCache *
    folks_avatar_cache_dup (void);

Create or return the singleton FolksAvatarCache class instance. If the instance doesn't exist already, it will be created.

This function is thread-safe.

#### Returns

Singleton FolksAvatarCache instance

Since: 0.6.0

## Types and Values

### FOLKS_TYPE_AVATAR_CACHE

    #define FOLKS_TYPE_AVATAR_CACHE (folks_avatar_cache_get_type ())

The type for FolksAvatarCache.

### struct FolksAvatarCache

    struct FolksAvatarCache {
    	GObject parent_instance;
    	FolksAvatarCachePrivate * priv;
    };

A singleton persistent cache for avatars in folks.

Avatars may be added to the cache, and referred to by a persistent URI from that point onwards. The avatars will be stored on disk in the user's XDG cache directory.

The avatar cache is typically used by backends where retrieving avatars is an expensive operation (for example, they have to be downloaded from the network every time they're used).

All avatars from all users of the FolksAvatarCache are stored in the same namespace, so callers must ensure that the IDs they use for avatars are globally unique (e.g. by using the corresponding "uid").

Ongoing store operations (`folks_avatar_cache_store_avatar()`) are rate limited to try and prevent file descriptor exhaustion. Load operations (`folks_avatar_cache_load_avatar()`) must be rate limited by the client, as the file I/O occurs when calling ``g_loadable_icon_load()`` rather than when retrieving the GLoadableIcon from the cache.

Since: 0.6.0

### struct FolksAvatarCacheClass

    struct FolksAvatarCacheClass {
    	GObjectClass parent_class;
    };

The class structure for `FOLKS_TYPE_AVATAR_CACHE`. All the fields in this structure are private and should never be accessed directly.

#### Members