---
name: "Memcached::libmemcached::memcached_callback"
section: "3pm"
platform: "linux"
package: "libmemcached-libmemcached-perl"
version: "1.001801+dfsg-5+b2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Memcached::libmemcached::memcached_callback"
---

# Memcached::libmemcached::memcached\_callback(3pm)

Get and set a callback

## NAME

memcached\_callback\_get, memcached\_callback\_set - Get and set a callback

## LIBRARY

C Client Library for memcached (libmemcached, -lmemcached)

## SYNOPSIS

```
  #include <memcached.h>
  memcached_return_t
    memcached_callback_set (memcached_st *ptr,
                            memcached_callback_t flag,
                            void *data);
  void *
    memcached_callback_get (memcached_st *ptr,
                            memcached_callback_t flag,
                            memcached_return_t *error);
```

## DESCRIPTION

[**libmemcached**(3)](/libmemcached/3.md) can have callbacks set key execution points. These either provide function calls at points in the code, or return pointers to structures for particular usages.

**memcached\_callback\_get()** takes a callback flag and returns the structure or function set by **memcached\_callback\_set()**.

**memcached\_callback\_set()** changes the function/structure assigned by a callback flag. No connections are reset.

You can use MEMCACHED\_CALLBACK\_USER\_DATA to provide custom context if required for any  of the callbacks

- MEMCACHED\_CALLBACK\_CLEANUP\_FUNCTION

  When **memcached\_delete()** is called this function will be executed. At the point of its execution all connections have been closed.

- MEMCACHED\_CALLBACK\_CLONE\_FUNCTION

  When **memcached\_delete()** is called this function will be executed. At the point of its execution all connections have been closed.

- MEMCACHED\_CALLBACK\_PREFIX\_KEY

  You can set a value which will be used to create a domain for your keys. The value specified here will be prefixed to each of your keys. The value can not be greater then MEMCACHED\_PREFIX\_KEY\_MAX\_SIZE - 1 and will reduce MEMCACHED\_MAX\_KEY by the value of your key. The prefix key is only applied to the primary key, not the master key. MEMCACHED\_FAILURE will be returned if no key is set. In the case of a key which is too long MEMCACHED\_BAD\_KEY\_PROVIDED will be returned.

- MEMCACHED\_CALLBACK\_USER\_DATA

  This allows you to store a pointer to a specifc piece of data. This can be retrieved from inside of **memcached\_fetch\_execute()**. Cloning a memcached\_st will copy the pointer to the clone.

- MEMCACHED\_CALLBACK\_MALLOC\_FUNCTION

  DEPRECATED: use memcached\_set\_memory\_allocators instead.

- MEMCACHED\_CALLBACK\_REALLOC\_FUNCTION

  DEPRECATED: use memcached\_set\_memory\_allocators instead.

- MEMCACHED\_CALLBACK\_FREE\_FUNCTION

  DEPRECATED: use memcached\_set\_memory\_allocators instead.

- MEMCACHED\_CALLBACK\_GET\_FAILURE

  This function implements the read through cache behavior. On failure of retrieval this callback will be called.  You are responsible for populating the result object provided. This result object will then be stored in the server and returned to the calling process. You must clone the memcached\_st in order to make use of it. The value will be stored only if you return MEMCACHED\_SUCCESS or MEMCACHED\_BUFFERED. Returning MEMCACHED\_BUFFERED will cause the object to be buffered and not sent immediately (if this is the default behavior based on your connection setup this will happen automatically).

  The prototype for this is: memcached\_return\_t (\*memcached\_trigger\_key)(memcached\_st \*ptr, char \*key, size\_t key\_length, memcached\_result\_st \*result);

- MEMCACHED\_CALLBACK\_DELETE\_TRIGGER

  This function implements a trigger upon successful deletion of a key. The memcached\_st structure will need to be cloned in order to make use of it.

  The prototype for this is: typedef memcached\_return\_t (\*memcached\_trigger\_delete\_key)(memcached\_st \*ptr, char \*key, size\_t key\_length);

## RETURN

**memcached\_callback\_get()** return the function or structure that was provided. Upon error, nothing is set, null is returned, and the memcached\_return\_t argument is set to MEMCACHED\_FAILURE.

**memcached\_callback\_set()** returns MEMCACHED\_SUCCESS upon successful setting, otherwise MEMCACHED\_FAILURE on error.

## HOME

To find out more information please check: \<https://launchpad.net/libmemcached\>

## AUTHOR

Brian Aker, \<brian@tangent.org\>

## SEE ALSO

[**memcached**(1)](/memcached/1.md) [**libmemcached**(3)](/libmemcached/3.md) [**memcached\_strerror**(3)](/memcached_strerror/3.md)
