From: Date: Sat, 22 Mar 2008 04:54:01 +0000 (-0700) Subject: Adding support for trigger call on delete of a successful object. X-Git-Tag: _20~1^2~41 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=26aff973ea8db6495862e66cb287e9c000103c9e;p=m6w6%2Flibmemcached Adding support for trigger call on delete of a successful object. --- diff --git a/ChangeLog b/ChangeLog index 7c7828f6..fd539d39 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ * Read through cached support. * Fixed for cas by key operation. * Fix for memcached_server_st list structures to have correct count. + * Added callback MEMCACHED_CALLBACK_DELETE_TRIGGER 0.18 Sun Mar 16 21:57:55 PDT 2008 diff --git a/docs/memcached_callback.pod b/docs/memcached_callback.pod index 56ba4e29..a9c0ac41 100755 --- a/docs/memcached_callback.pod +++ b/docs/memcached_callback.pod @@ -53,28 +53,28 @@ 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. -=item MEMCACHED_CALLBACK_MALLOC_FUNCTION, +=item MEMCACHED_CALLBACK_MALLOC_FUNCTION This alllows yout to pass in a customized version of malloc that will be used instead of the builtin malloc(3) call. The prototype for this is: void *(*memcached_malloc_function)(memcached_st *ptr, const size_t size); -=item MEMCACHED_CALLBACK_REALLOC_FUNCTION, +=item MEMCACHED_CALLBACK_REALLOC_FUNCTION This alllows yout to pass in a customized version of realloc that will be used instead of the builtin realloc(3) call. The prototype for this is: void *(*memcached_realloc_function)(memcached_st *ptr, void *mem, const size_t size); -=item MEMCACHED_CALLBACK_FREE_FUNCTION, +=item MEMCACHED_CALLBACK_FREE_FUNCTION This alllows yout to pass in a customized version of realloc that will be used instead of the builtin free(3) call. The prototype for this is: typedef void (*memcached_free_function)(memcached_st *ptr, void *mem); -=item MEMCACHED_CALLBACK_GET_FAILURE, +=item 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 @@ -86,6 +86,15 @@ cause the object to be buffered and not sent immediatly (if this is the default The prototype for this is: memcached_return (*memcached_trigger_key)(memcached_st *ptr, char *key, size_t key_length, memcached_result_st *result); +=item 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 (*memcached_trigger_delete_key)(memcached_st *ptr, char *key, size_t key_length); + + =back =head1 RETURN diff --git a/libmemcached/memcached.c b/libmemcached/memcached.c index 2c8cef75..33a80bab 100644 --- a/libmemcached/memcached.c +++ b/libmemcached/memcached.c @@ -103,6 +103,7 @@ memcached_st *memcached_clone(memcached_st *clone, memcached_st *ptr) new_clone->call_malloc= ptr->call_malloc; new_clone->call_realloc= ptr->call_realloc; new_clone->get_key_failure= ptr->get_key_failure; + new_clone->delete_trigger= ptr->delete_trigger; if (ptr->on_clone) ptr->on_clone(ptr, new_clone); diff --git a/libmemcached/memcached.h b/libmemcached/memcached.h index 2df0b7ae..b84d4373 100644 --- a/libmemcached/memcached.h +++ b/libmemcached/memcached.h @@ -83,6 +83,7 @@ struct memcached_st { memcached_malloc_function call_malloc; memcached_realloc_function call_realloc; memcached_trigger_key get_key_failure; + memcached_trigger_delete_key delete_trigger; #ifdef NOT_USED /* Future Use */ uint8_t replicas; memcached_return warning; diff --git a/libmemcached/memcached_callback.c b/libmemcached/memcached_callback.c index ad21c10d..6db2db82 100644 --- a/libmemcached/memcached_callback.c +++ b/libmemcached/memcached_callback.c @@ -54,6 +54,12 @@ memcached_return memcached_callback_set(memcached_st *ptr, ptr->get_key_failure= func; break; } + case MEMCACHED_CALLBACK_DELETE_TRIGGER: + { + memcached_trigger_delete_key func= (memcached_trigger_delete_key)data; + ptr->delete_trigger= func; + break; + } default: return MEMCACHED_FAILURE; } @@ -106,6 +112,11 @@ void *memcached_callback_get(memcached_st *ptr, *error= ptr->get_key_failure ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE; return (void *)ptr->get_key_failure; } + case MEMCACHED_CALLBACK_DELETE_TRIGGER: + { + *error= ptr->delete_trigger ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE; + return (void *)ptr->delete_trigger; + } default: WATCHPOINT_ASSERT(0); *error= MEMCACHED_FAILURE; diff --git a/libmemcached/memcached_constants.h b/libmemcached/memcached_constants.h index 6f3909b6..254e9116 100644 --- a/libmemcached/memcached_constants.h +++ b/libmemcached/memcached_constants.h @@ -91,6 +91,7 @@ typedef enum { MEMCACHED_CALLBACK_REALLOC_FUNCTION, MEMCACHED_CALLBACK_FREE_FUNCTION, MEMCACHED_CALLBACK_GET_FAILURE, + MEMCACHED_CALLBACK_DELETE_TRIGGER, } memcached_callback; typedef enum { diff --git a/libmemcached/memcached_delete.c b/libmemcached/memcached_delete.c index 60e3bed4..37a28add 100644 --- a/libmemcached/memcached_delete.c +++ b/libmemcached/memcached_delete.c @@ -59,6 +59,9 @@ memcached_return memcached_delete_by_key(memcached_st *ptr, rc= MEMCACHED_SUCCESS; } + if (rc == MEMCACHED_SUCCESS && ptr->delete_trigger) + ptr->delete_trigger(ptr, key, key_length); + error: LIBMEMCACHED_MEMCACHED_DELETE_END(); return rc; diff --git a/libmemcached/memcached_types.h b/libmemcached/memcached_types.h index 6db4ba45..de0709ba 100644 --- a/libmemcached/memcached_types.h +++ b/libmemcached/memcached_types.h @@ -28,6 +28,8 @@ typedef memcached_return (*memcached_server_function)(memcached_st *ptr, memcach typedef memcached_return (*memcached_trigger_key)(memcached_st *ptr, char *key, size_t key_length, memcached_result_st *result); +typedef memcached_return (*memcached_trigger_delete_key)(memcached_st *ptr, + char *key, size_t key_length); #ifdef __cplusplus } diff --git a/tests/function.c b/tests/function.c index 9e10552c..38de6679 100644 --- a/tests/function.c +++ b/tests/function.c @@ -584,6 +584,26 @@ uint8_t read_through(memcached_st *memc) return 0; } +memcached_return delete_trigger(memcached_st *ptr, char *key, size_t key_length) +{ + assert(key); + + return MEMCACHED_SUCCESS; +} + +uint8_t delete_through(memcached_st *memc) +{ + memcached_trigger_delete_key callback; + memcached_return rc; + + callback= delete_trigger; + + rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_DELETE_TRIGGER, callback); + assert(rc == MEMCACHED_SUCCESS); + + return 0; +} + uint8_t get_test(memcached_st *memc) { memcached_return rc; @@ -2531,6 +2551,7 @@ test_st tests[] ={ {"bad_key", 1, bad_key_test }, {"memcached_server_cursor", 1, memcached_server_cursor_test }, {"read_through", 1, read_through }, + {"delete_through", 1, delete_through }, {0, 0, 0} };