FolksObjectCache

FolksObjectCache — A generic abstract cache for sets of objects. This can be used by subclasses to implement caching of homogeneous sets of objects. Subclasses simply have to implement serialisation and deserialisation of the objects to and from GVariants.

Synopsis

#define             FOLKS_TYPE_OBJECT_CACHE
GVariantType *      folks_object_cache_get_serialised_object_type
                                                        (FolksObjectCache *self,
                                                         guint8 object_version);
guint8              folks_object_cache_get_serialised_object_version
                                                        (FolksObjectCache *self);
GVariant *          folks_object_cache_serialise_object (FolksObjectCache *self,
                                                         gconstpointer object);
gpointer            folks_object_cache_deserialise_object
                                                        (FolksObjectCache *self,
                                                         GVariant *variant,
                                                         guint8 object_version);
void                folks_object_cache_load_objects     (FolksObjectCache *self,
                                                         GCancellable *cancellable,
                                                         GAsyncReadyCallback _callback_,
                                                         gpointer _user_data_);
GeeSet *            folks_object_cache_load_objects_finish
                                                        (FolksObjectCache *self,
                                                         GAsyncResult *_res_);
void                folks_object_cache_store_objects    (FolksObjectCache *self,
                                                         GeeSet *objects,
                                                         GCancellable *cancellable,
                                                         GAsyncReadyCallback _callback_,
                                                         gpointer _user_data_);
void                folks_object_cache_store_objects_finish
                                                        (FolksObjectCache *self,
                                                         GAsyncResult *_res_);
void                folks_object_cache_clear_cache      (FolksObjectCache *self,
                                                         GAsyncReadyCallback _callback_,
                                                         gpointer _user_data_);
void                folks_object_cache_clear_cache_finish
                                                        (FolksObjectCache *self,
                                                         GAsyncResult *_res_);
const gchar *       folks_object_cache_get_type_id      (FolksObjectCache *self);
const gchar *       folks_object_cache_get_id           (FolksObjectCache *self);
struct              FolksObjectCache;

Object Hierarchy

  GObject
   +----FolksObjectCache

Properties

  "id"                       gchar*                : Read / Write / Construct Only
  "t-destroy-func"           gpointer              : Write / Construct Only
  "t-dup-func"               gpointer              : Write / Construct Only
  "t-type"                   GType*                : Write / Construct Only
  "type-id"                  gchar*                : Read / Write / Construct Only

Description

It's intended that this class be used for providing caching layers for FolksPersonaStores, for example.

Details

FOLKS_TYPE_OBJECT_CACHE

#define FOLKS_TYPE_OBJECT_CACHE (folks_object_cache_get_type ())

The type for FolksObjectCache.


folks_object_cache_get_serialised_object_type ()

GVariantType *      folks_object_cache_get_serialised_object_type
                                                        (FolksObjectCache *self,
                                                         guint8 object_version);

Get the GVariantType of the serialised form of an object stored in this cache.

If a smooth upgrade path is needed in future due to cache file format changes, this may be modified to take a version parameter.

self :

the FolksObjectCache instance

object_version :

the version of the object format to use, or `uint8.MAX` for the latest version. [in]

Returns :

variant type for that object version, or `null` if the version is unsupported

Since 0.6.0


folks_object_cache_get_serialised_object_version ()

guint8              folks_object_cache_get_serialised_object_version
                                                        (FolksObjectCache *self);

Get the version of the variant type returned by folks_object_cache_get_serialised_object_type(). This must be incremented every time the variant type changes so that old cache files aren't misinterpreted.

self :

the FolksObjectCache instance

Since 0.6.0


folks_object_cache_serialise_object ()

GVariant *          folks_object_cache_serialise_object (FolksObjectCache *self,
                                                         gconstpointer object);

Serialise the given `object` to a GVariant and return the variant. The variant must be of the type returned by folks_object_cache_get_serialised_object_type().

self :

the FolksObjectCache instance

object :

the object to serialise. [in]

Returns :

serialised form of `object`

Since 0.6.0


folks_object_cache_deserialise_object ()

gpointer            folks_object_cache_deserialise_object
                                                        (FolksObjectCache *self,
                                                         GVariant *variant,
                                                         guint8 object_version);

Deserialise the given `variant` to a new instance of an object. The variant is guaranteed to have the type returned by folks_object_cache_get_serialised_object_type().

self :

the FolksObjectCache instance

variant :

the serialised form to deserialise. [in]

object_version :

the version of the object format to deserialise from. [in]

Returns :

the deserialised object

Since 0.6.0


folks_object_cache_load_objects ()

void                folks_object_cache_load_objects     (FolksObjectCache *self,
                                                         GCancellable *cancellable,
                                                         GAsyncReadyCallback _callback_,
                                                         gpointer _user_data_);

Load a set of objects from the cache and return them as a new set. If the cache file doesn't exist, `null` will be returned. An empty set will be returned if the cache file existed but was empty (i.e. was stored with an empty set originally).

Loading the objects can be cancelled using `cancellable`. If it is, `null` will be returned.

If any errors are encountered while loading the objects, warnings will be logged as appropriate and `null` will be returned.

See also: folks_object_cache_load_objects_finish()

self :

the FolksObjectCache instance

cancellable :

A GCancellable for the operation, or `null`. [in][allow-none]

_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_object_cache_load_objects_finish ()

GeeSet *            folks_object_cache_load_objects_finish
                                                        (FolksObjectCache *self,
                                                         GAsyncResult *_res_);

Load a set of objects from the cache and return them as a new set. If the cache file doesn't exist, `null` will be returned. An empty set will be returned if the cache file existed but was empty (i.e. was stored with an empty set originally).

Loading the objects can be cancelled using `cancellable`. If it is, `null` will be returned.

If any errors are encountered while loading the objects, warnings will be logged as appropriate and `null` will be returned.

See also: folks_object_cache_load_objects()

self :

the FolksObjectCache instance

_res_ :

a GAsyncResult

Returns :

A set of objects from the cache, or `null`.

Since 0.6.0


folks_object_cache_store_objects ()

void                folks_object_cache_store_objects    (FolksObjectCache *self,
                                                         GeeSet *objects,
                                                         GCancellable *cancellable,
                                                         GAsyncReadyCallback _callback_,
                                                         gpointer _user_data_);

Store a set of objects to the cache file, overwriting any existing set of objects in the cache, or creating the cache file from scratch if it didn't previously exist.

Storing the objects can be cancelled using `cancellable`. If it is, the cache will be left in a consistent state, but may be storing the old set of objects or the new set.

See also: folks_object_cache_store_objects_finish()

self :

the FolksObjectCache instance

objects :

A set of objects to store. This may be empty, but may not be `null`. [in]

cancellable :

A GCancellable for the operation, or `null`. [in][allow-none]

_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_object_cache_store_objects_finish ()

void                folks_object_cache_store_objects_finish
                                                        (FolksObjectCache *self,
                                                         GAsyncResult *_res_);

Store a set of objects to the cache file, overwriting any existing set of objects in the cache, or creating the cache file from scratch if it didn't previously exist.

Storing the objects can be cancelled using `cancellable`. If it is, the cache will be left in a consistent state, but may be storing the old set of objects or the new set.

See also: folks_object_cache_store_objects()

self :

the FolksObjectCache instance

_res_ :

a GAsyncResult

Since 0.6.0


folks_object_cache_clear_cache ()

void                folks_object_cache_clear_cache      (FolksObjectCache *self,
                                                         GAsyncReadyCallback _callback_,
                                                         gpointer _user_data_);

Clear this cache object, deleting its backing file.

See also: folks_object_cache_clear_cache_finish()

self :

the FolksObjectCache instance

_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_object_cache_clear_cache_finish ()

void                folks_object_cache_clear_cache_finish
                                                        (FolksObjectCache *self,
                                                         GAsyncResult *_res_);

Clear this cache object, deleting its backing file.

See also: folks_object_cache_clear_cache()

self :

the FolksObjectCache instance

_res_ :

a GAsyncResult

Since 0.6.0


folks_object_cache_get_type_id ()

const gchar *       folks_object_cache_get_type_id      (FolksObjectCache *self);

self :

the FolksObjectCache instance to query

Returns :

the value of the "type-id" property

folks_object_cache_get_id ()

const gchar *       folks_object_cache_get_id           (FolksObjectCache *self);

self :

the FolksObjectCache instance to query

Returns :

the value of the "id" property

struct FolksObjectCache

struct FolksObjectCache;

A generic abstract cache for sets of objects. This can be used by subclasses to implement caching of homogeneous sets of objects. Subclasses simply have to implement serialisation and deserialisation of the objects to and from GVariants.

It's intended that this class be used for providing caching layers for FolksPersonaStores, for example.

Since 0.6.0

Property Details

The "id" property

  "id"                       gchar*                : Read / Write / Construct Only

A string identifying the particular cache instance.

This will form the file name of the cache file, but will be escaped beforehand, so can be an arbitrary non-empty string.

Default value: NULL

Since 0.6.6


The "t-destroy-func" property

  "t-destroy-func"           gpointer              : Write / Construct Only

destroy func.


The "t-dup-func" property

  "t-dup-func"               gpointer              : Write / Construct Only

dup func.


The "t-type" property

  "t-type"                   GType*                : Write / Construct Only

type.

Allowed values: void


The "type-id" property

  "type-id"                  gchar*                : Read / Write / Construct Only

A string identifying the type of object being cached.

This has to be suitable for use as a directory name; i.e. lower case, hyphen-separated tokens.

Default value: NULL

Since 0.6.6