) {
item_t *item;
- item = search(cache, key);
- if (item) {
- hit(cache, item);
- return (int)item->value;
+ if (cache) {
+ item = search(cache, key);
+ if (item) {
+ hit(cache, item);
+ return (int)item->value;
+ }
}
return -ENOENT;
}
) {
cache_t *c = *cache, *nc;
- if (c)
- while (c->used > newsize)
- drop_lre(c);
+ if (newsize == 0) {
+ free(c);
+ nc = NULL;
+ } else {
+ if (c)
+ while (c->used > newsize)
+ drop_lre(c);
- nc = realloc(c, newsize - 1 + sizeof *c);
- if (nc == NULL)
- return -ENOMEM;
+ nc = realloc(c, newsize - 1 + sizeof *c);
+ if (nc == NULL)
+ return -ENOMEM;
- nc->count = newsize;
- if (!c) {
- nc->cacheid = 0;
- nc->used = 0;
+ nc->count = newsize;
+ if (!c) {
+ nc->cacheid = 0;
+ nc->used = 0;
+ }
}
*cache = nc;
return 0;
}
-
cache_t **cache,
uint32_t size
);
-
-
-
int cynara_admin_initialize(struct cynara_admin **pp_cynara_admin)
{
- return from_status(rcyn_open((rcyn_t**)pp_cynara_admin, rcyn_Admin, 0, 0));
+ return from_status(rcyn_open((rcyn_t**)pp_cynara_admin, rcyn_Admin, 1, 0));
}
int cynara_admin_finish(struct cynara_admin *p_cynara_admin)
if (p_cynara == NULL)
ret = CYNARA_API_OUT_OF_MEMORY;
else {
- ret = from_status(rcyn_open(&p_cynara->rcyn, rcyn_Check, p_conf ? p_conf->szcache : 0, 0));
+ ret = from_status(rcyn_open(&p_cynara->rcyn, rcyn_Check, p_conf ? p_conf->szcache : 1, 0));
if (ret != CYNARA_API_SUCCESS)
free(p_cynara);
else {
int cynara_initialize(cynara **pp_cynara, const cynara_configuration *p_conf)
{
- return from_status(rcyn_open((rcyn_t**)pp_cynara, rcyn_Check, p_conf ? p_conf->szcache : 0, 0));
+ return from_status(rcyn_open((rcyn_t**)pp_cynara, rcyn_Check, p_conf ? p_conf->szcache : 1, 0));
}
int cynara_finish(cynara *p_cynara)
#include "socket.h"
#define MIN_CACHE_SIZE 400
+#define CACHESIZE(x) ((x) >= MIN_CACHE_SIZE ? (x) : (x) ? MIN_CACHE_SIZE : 0)
struct asreq;
typedef struct asreq asreq_t;
strcpy((char*)(rcyn+1), socketspec);
/* record type and weakly create cache */
- cache_create(&rcyn->cache, cache_size < MIN_CACHE_SIZE ? MIN_CACHE_SIZE : cache_size);
+ cache_create(&rcyn->cache, CACHESIZE(cache_size));
rcyn->type = type;
rcyn->socketspec = socketspec;
rcyn->async.controlcb = NULL;
rc = wait_pending_reply(rcyn);
if (rc >= 0) {
rc = status_check(rcyn, &expire);
- if (rc >= 0)
+ if (rcyn->cache && rc >= 0)
cache_put(rcyn->cache, key, rc, expire);
}
}
rcyn_t *rcyn,
uint32_t size
) {
- return cache_resize(&rcyn->cache, size < MIN_CACHE_SIZE ? MIN_CACHE_SIZE : size);
+ return cache_resize(&rcyn->cache, CACHESIZE(size));
}
void
c->s agent NAME [ARGS...]
s->c done|error ...
-asking (agent ask CLIENT SESSION USER PERMISSION):
+ask agent (agent):
- s->c ask CLIENT SESSION USER PERMISSION
+ s->c ask NAME VALUE CLIENT SESSION USER PERMISSION
c->s done | ([yes|no] [always|session|one-time|EXPIRE])