refcache.h File Reference

A simple reference cache. More...

`#include <gutenprint/string-list.h>`

## Functions

int | stp_refcache_create (const char *name)
| Create a new object cache.
void * | stp_refcache_find_item (const char *cache, const char *item)
| Find an item in a cache.
int | stp_refcache_add_item (const char *cache, const char *item, void *data)
| Add an item to a cache.
void | stp_refcache_remove_item (const char *cache, const char *item)
| Remove an item from cache.
void | stp_refcache_replace_item (const char *cache, const char *item, void *data)
| Replace an item's data, or add if it doesn't exist.
void | stp_refcache_destroy (const char *cache)
| Destroy a cache.
const stp_string_list_t * | stp_refcache_list_caches (void)
| Return a static list of all caches in existence.
const stp_string_list_t * | stp_refcache_list_cache_items (const char *cache)
| Return a static list of items in a specified cache.

## Detailed Description

A simple reference cache.

## Function Documentation

## stp_refcache_add_item()

int stp_refcache_add_item | ( | const char * | cache,
|  | const char * | item,
|  | void * | data )

extern

Add an item to a cache.

Parameters

  cache | the cache to use or create.
  item | the name of the item to cache
  data | pointer to the data item to store

Returns
  true if item added; false if already exists

## stp_refcache_create()

int stp_refcache_create | ( | const char * | name | ) |

extern

Create a new object cache.

Parameters

  name | The name of the cache to create

Returns
  True if created, false if cache already exists.

## stp_refcache_destroy()

void stp_refcache_destroy | ( | const char * | cache | ) |

extern

Destroy a cache.

The individual items are not freed. If cache does not exist this is a no-op.

Parameters

  cache | the cache to destroy.

## stp_refcache_find_item()

void * stp_refcache_find_item | ( | const char * | cache,
|  | const char * | item )

extern

Find an item in a cache.

Parameters

  cache | the cache to use.
  item | the name of the item to cache

Returns
  item if exists, NULL otherwise

## stp_refcache_list_cache_items()

const stp_string_list_t * stp_refcache_list_cache_items | ( | const char * | cache | ) |

extern

Return a static list of items in a specified cache.

Parameters

  cache | name of cache

Returns
  list of items in cache or NULL if cache does not exist

## stp_refcache_list_caches()

const stp_string_list_t * stp_refcache_list_caches | ( | void |  | ) |

extern

Return a static list of all caches in existence.

Returns
  list of caches in existence

## stp_refcache_remove_item()

void stp_refcache_remove_item | ( | const char * | cache,
|  | const char * | item )

extern

Remove an item from cache.

The item's data is not freed. If cache or item does not exist this is a no-op.

Parameters

  cache | the cache to use.
  item | the name of the item to remove from cache

## stp_refcache_replace_item()

void stp_refcache_replace_item | ( | const char * | cache,
|  | const char * | item,
|  | void * | data )

extern

Replace an item's data, or add if it doesn't exist.

The old data (if any) is not freed. Fails if cache does not already exist.

Parameters

  cache | the cache to use.
  item | the name of the item to add/update.
  data | the data to be added/updated for the cached item.