Memcac...allback(3pm)

🌸 NAME 🌸

memcached_callback_get, memcached_callback_set β€” bestie, these are the get-and-set pair for callbacks, no cap πŸ’–


πŸ“š LIBRARY πŸ“š

C Client Library for memcached (libmemcached, -lmemcached) β€” yes she's giving C, she's giving <memcached.h>, she's giving iconic πŸŽ€


✨ 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 πŸ’…

okay so libmemcached(3) can have callbacks set at key execution points πŸ¦‹ and like, they do one of two things: either they give you function calls at specific points in the code, or they hand you back pointers to structures for particular usages. both. it's giving versatile queen ✨

memcached_callback_get() takes a callback flag and returns the structure or function that memcached_callback_set() set. literally just a "hey what's currently in here" vibe check πŸ‘‘

memcached_callback_set() changes the function/structure assigned by a callback flag. heads up bestie β€” no connections are reset when you do this. periodt.

you can use MEMCACHED_CALLBACK_USER_DATA to provide custom context if you need it for any of the callbacks 🫢

🌈 the callback flags, one by one 🌈

  • 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. (yes that's the actual wording, twice in this doc, and no we're not gonna lie about it 😭)
  • 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. (same energy as above, fr fr)
  • MEMCACHED_CALLBACK_PREFIX_KEY β€” you can set a value which will be used to create a domain for your keys πŸ’– the value specified here gets prefixed to each of your keys. the value can not be greater then MEMCACHED_PREFIX_KEY_MAX_SIZE - 1, and it 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. and if your key is too long? MEMCACHED_BAD_KEY_PROVIDED gets returned. she said know your limits πŸ’€
  • MEMCACHED_CALLBACK_USER_DATA β€” this lets you store a pointer to a specifc piece of data (their spelling, not mine, leave her alone πŸ™ˆ). you can retrieve it from inside of memcached_fetch_execute(). and cloning a memcached_st will copy the pointer to the clone. so cute πŸŽ€
  • MEMCACHED_CALLBACK_MALLOC_FUNCTION β€” DEPRECATED: use memcached_set_memory_allocators instead. she's retired, respect her legacy πŸ’œ
  • MEMCACHED_CALLBACK_REALLOC_FUNCTION β€” DEPRECATED: use memcached_set_memory_allocators instead. same thing, diff function name, don't use her ⭐
  • MEMCACHED_CALLBACK_FREE_FUNCTION β€” DEPRECATED: use memcached_set_memory_allocators instead. yes the whole trio is deprecated, we said what we said πŸ¦‹
  • 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 (main character responsibility, no cap). 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 β€” and ngl, 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. (again. clone. always clone. it's a theme ✨)

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() returns 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. so like, check your error pointer, bestie, it's literally right there 😭

memcached_callback_set() returns MEMCACHED_SUCCESS upon successful setting, otherwise MEMCACHED_FAILURE on error. that's it, that's the whole vibe check πŸ‘‘


🌈 HOME 🌈

to find out more information please check: <https://launchpad.net/libmemcached> β€” go read, it's giving lore πŸ’œ


πŸ‘‘ AUTHOR πŸ‘‘

Brian Aker, <brian@tangent.org> β€” the icon, the legend, the main character who wrote this πŸ’…


πŸ¦‹ SEE ALSO πŸ¦‹

memcached(1) libmemcached(3) memcached_strerror(3) β€” the whole friend group, go say hi ✨


k bye bestie πŸ’– this page came to you courtesy of User Contributed Perl Documentation, shipped as perl v5.42.3, dated 2026-08-19, and the title card on this one is Memcac...allback(3pm) (yes, they truncated it, not me 🫢). slay, go set some callbacks, and remember: clone your memcached_st πŸ”₯

πŸ“¦ where this page comes from