The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Functions | Variables
rlm_cache_memcached.c File Reference

memcached based cache. More...

#include <libmemcached/memcached.h>
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/module_rlm.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/value.h>
#include "../../rlm_cache.h"
#include "../../serialize.h"
+ Include dependency graph for rlm_cache_memcached.c:

Go to the source code of this file.

Data Structures

struct  rlm_cache_memcached_handle_t
 
struct  rlm_cache_memcached_t
 

Macros

#define LOG_PREFIX   "cache - memcached"
 

Functions

static int _mod_conn_free (rlm_cache_memcached_handle_t *mandle)
 Free a connection handle. More...
 
static cache_status_t cache_entry_expire (UNUSED rlm_cache_config_t const *config, UNUSED void *instance, request_t *request, void *handle, fr_value_box_t const *key)
 Call delete the cache entry from memcached. More...
 
static cache_status_t cache_entry_find (rlm_cache_entry_t **out, UNUSED rlm_cache_config_t const *config, UNUSED void *instance, request_t *request, void *handle, fr_value_box_t const *key)
 Locate a cache entry in memcached. More...
 
static void cache_entry_free (rlm_cache_entry_t *c)
 Locate a cache entry in memcached. More...
 
static cache_status_t cache_entry_insert (UNUSED rlm_cache_config_t const *config, UNUSED void *instance, request_t *request, void *handle, const rlm_cache_entry_t *c)
 Insert a new entry into the data store. More...
 
static void * mod_conn_create (TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout)
 Create a new memcached handle. More...
 
static int mod_conn_get (void **handle, UNUSED rlm_cache_config_t const *config, void *instance, request_t *request)
 Get a memcached handle. More...
 
static int mod_conn_reconnect (void **handle, UNUSED rlm_cache_config_t const *config, void *instance, request_t *request)
 Reconnect a memcached handle. More...
 
static void mod_conn_release (UNUSED rlm_cache_config_t const *config, void *instance, request_t *request, rlm_cache_handle_t *handle)
 Release a memcached handle. More...
 
static int mod_instantiate (module_inst_ctx_t const *mctx)
 Create a new rlm_cache_memcached instance. More...
 
static int mod_load (void)
 

Variables

static const conf_parser_t driver_config []
 
rlm_cache_driver_t rlm_cache_memcached
 

Detailed Description

memcached based cache.

Id
71490b5f2d438b54bf0c075fbd928534c67112d2

Definition in file rlm_cache_memcached.c.


Data Structure Documentation

◆ rlm_cache_memcached_handle_t

struct rlm_cache_memcached_handle_t

Definition at line 37 of file rlm_cache_memcached.c.

Data Fields
memcached_st * handle

◆ rlm_cache_memcached_t

struct rlm_cache_memcached_t

Definition at line 41 of file rlm_cache_memcached.c.

+ Collaboration diagram for rlm_cache_memcached_t:
Data Fields
char const * options Connection options.
fr_pool_t * pool

Macro Definition Documentation

◆ LOG_PREFIX

#define LOG_PREFIX   "cache - memcached"

Definition at line 25 of file rlm_cache_memcached.c.

Function Documentation

◆ _mod_conn_free()

static int _mod_conn_free ( rlm_cache_memcached_handle_t mandle)
static

Free a connection handle.

Parameters
mandleto free.

Definition at line 55 of file rlm_cache_memcached.c.

+ Here is the caller graph for this function:

◆ cache_entry_expire()

static cache_status_t cache_entry_expire ( UNUSED rlm_cache_config_t const *  config,
UNUSED void *  instance,
request_t request,
void *  handle,
fr_value_box_t const *  key 
)
static

Call delete the cache entry from memcached.

Note
This callback is not optional.
Parameters
[in]configfor this instance of the rlm_cache module.
[in]instanceDriver specific instance data.
[in]requestThe current request.
[in]handlethe driver gave us when we called cache_acquire_t, or NULL if no cache_acquire_t callback was provided.
[in]keyof entry to expire.
Returns

Definition at line 246 of file rlm_cache_memcached.c.

◆ cache_entry_find()

static cache_status_t cache_entry_find ( rlm_cache_entry_t **  out,
UNUSED rlm_cache_config_t const *  config,
UNUSED void *  instance,
request_t request,
void *  handle,
fr_value_box_t const *  key 
)
static

Locate a cache entry in memcached.

If a cache entry is found, but the cache entry needs to be deserialized, the driver is expected to allocate an appropriately sized rlm_cache_entry_t, perform the deserialisation, and write a pointer to the new entry to out, returning CACHE_OK.

If the rlm_cache_handle_t is inviable, the driver should return CACHE_RECONNECT, to have it reinitialised/reconnected.

Parameters
[out]outWhere to write a pointer to the retrieved entry (if there was one).
[in]configfor this instance of the rlm_cache module.
[in]instanceDriver specific instance data.
[in]requestThe current request.
[in]handlethe driver gave us when we called cache_acquire_t, or NULL if no cache_acquire_t callback was provided.
[in]keyto use to lookup cache entry
Returns

Definition at line 159 of file rlm_cache_memcached.c.

+ Here is the call graph for this function:

◆ cache_entry_free()

static void cache_entry_free ( rlm_cache_entry_t c)
static

Locate a cache entry in memcached.

Note
This callback is optional, but the driver assume responsibility for freeing the cache_entry_t on cache_entry_expire_t.

If the driver does not need to keep a local copy of the cache entry, it should provide a callback to free the memory previously allocated for the cache entry by cache_entry_find_t or by rlm_cache.

Parameters
centry to free.

Definition at line 150 of file rlm_cache_memcached.c.

+ Here is the call graph for this function:

◆ cache_entry_insert()

static cache_status_t cache_entry_insert ( UNUSED rlm_cache_config_t const *  config,
UNUSED void *  instance,
request_t request,
void *  handle,
const rlm_cache_entry_t c 
)
static

Insert a new entry into the data store.

Serialize (if necessary) the entry passed to us, and write it to the cache with the key c->key.

The cache entry should not be freed by the driver, irrespective of success or failure. If the entry needs to be freed after insertion because a local copy should not be kept, the driver should provide a cache_entry_free_t callback.

If the rlm_cache_handle_t is inviable, the driver should return CACHE_RECONNECT, to have it reinitialised/reconnected.

Note
This callback is not optional.
This callback must overwrite existing cache entries on insert.
Parameters
configfor this instance of the rlm_cache module.
instanceDriver specific instance data.
requestThe current request.
handlethe driver gave us when we called cache_acquire_t, or NULL if no cache_acquire_t callback was provided.
cto insert.
Returns

Definition at line 209 of file rlm_cache_memcached.c.

+ Here is the call graph for this function:

◆ mod_conn_create()

static void* mod_conn_create ( TALLOC_CTX *  ctx,
void *  instance,
fr_time_delta_t  timeout 
)
static

Create a new memcached handle.

Definition at line 65 of file rlm_cache_memcached.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mod_conn_get()

static int mod_conn_get ( void **  handle,
UNUSED rlm_cache_config_t const *  config,
void *  instance,
request_t request 
)
static

Get a memcached handle.

Note
This callback is optional. If it's not provided the handle argument to other callbacks will be NULL.
Parameters
[out]handleWhere to write pointer to handle to access the cache with.
[in]configfor this instance of the rlm_cache module.
[in]instanceDriver specific instance data.
[in]requestThe current request.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 271 of file rlm_cache_memcached.c.

+ Here is the call graph for this function:

◆ mod_conn_reconnect()

static int mod_conn_reconnect ( void **  handle,
UNUSED rlm_cache_config_t const *  config,
void *  instance,
request_t request 
)
static

Reconnect a memcached handle.

Note
This callback is optional.
Parameters
[in,out]handleto reinitialise/reconnect.
[in]configfor this instance of the rlm_cache module.
[in]instanceDriver specific instance data.
[in]requestThe current request.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 305 of file rlm_cache_memcached.c.

+ Here is the call graph for this function:

◆ mod_conn_release()

static void mod_conn_release ( UNUSED rlm_cache_config_t const *  config,
void *  instance,
request_t request,
rlm_cache_handle_t handle 
)
static

Release a memcached handle.

Note
This callback is optional.
Parameters
[in]configfor this instance of the rlm_cache module.
[in]instanceDriver specific instance data.
[in]requestThe current request.
[in]handleto release.

Definition at line 293 of file rlm_cache_memcached.c.

+ Here is the call graph for this function:

◆ mod_instantiate()

static int mod_instantiate ( module_inst_ctx_t const *  mctx)
static

Create a new rlm_cache_memcached instance.

Parameters
[in]mctxData required for instantiation.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 108 of file rlm_cache_memcached.c.

+ Here is the call graph for this function:

◆ mod_load()

static int mod_load ( void  )
static

Definition at line 140 of file rlm_cache_memcached.c.

Variable Documentation

◆ driver_config

const conf_parser_t driver_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET("options", rlm_cache_memcached_t, options), .dflt = "--SERVER=localhost" },
}
#define CONF_PARSER_TERMINATOR
Definition: cf_parse.h:626
#define FR_CONF_OFFSET(_name, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition: cf_parse.h:268

Definition at line 46 of file rlm_cache_memcached.c.

◆ rlm_cache_memcached

rlm_cache_driver_t rlm_cache_memcached
Initial value:
= {
.common = {
.name = "cache_memcached",
.inst_size = sizeof(rlm_cache_memcached_t),
.onload = mod_load,
},
.insert = cache_entry_insert,
.expire = cache_entry_expire,
.acquire = mod_conn_get,
.release = mod_conn_release,
.reconnect = mod_conn_reconnect
}
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition: dl_module.h:65
static const conf_parser_t config[]
Definition: base.c:188
static cache_status_t cache_entry_expire(UNUSED rlm_cache_config_t const *config, UNUSED void *instance, request_t *request, void *handle, fr_value_box_t const *key)
Call delete the cache entry from memcached.
static int mod_load(void)
static int mod_conn_reconnect(void **handle, UNUSED rlm_cache_config_t const *config, void *instance, request_t *request)
Reconnect a memcached handle.
static cache_status_t cache_entry_insert(UNUSED rlm_cache_config_t const *config, UNUSED void *instance, request_t *request, void *handle, const rlm_cache_entry_t *c)
Insert a new entry into the data store.
static void mod_conn_release(UNUSED rlm_cache_config_t const *config, void *instance, request_t *request, rlm_cache_handle_t *handle)
Release a memcached handle.
static void cache_entry_free(rlm_cache_entry_t *c)
Locate a cache entry in memcached.
static cache_status_t cache_entry_find(rlm_cache_entry_t **out, UNUSED rlm_cache_config_t const *config, UNUSED void *instance, request_t *request, void *handle, fr_value_box_t const *key)
Locate a cache entry in memcached.
static const conf_parser_t driver_config[]
static int mod_conn_get(void **handle, UNUSED rlm_cache_config_t const *config, void *instance, request_t *request)
Get a memcached handle.
static int mod_instantiate(module_inst_ctx_t const *mctx)
Create a new rlm_cache_memcached instance.
static int instantiate(module_inst_ctx_t const *mctx)
Definition: rlm_rest.c:1312

Definition at line 322 of file rlm_cache_memcached.c.