c->no_redirects = 0;
c->cookies = 0;
c->saveAPDU_wrbuf = 0;
+
+#if HAVE_LIBMEMCACHED_MEMCACHED_H
+ c->mc_st = 0;
+#endif
return c;
}
yaz_cookies_destroy(c->cookies);
c->cookies = yaz_cookies_create();
+#if HAVE_LIBMEMCACHED_MEMCACHED_H
+ if (c->mc_st)
+ {
+ memcached_free(c->mc_st);
+ c->mc_st = 0;
+ }
+#endif
+ val = ZOOM_options_get(c->options, "memcached");
+ if (val && *val)
+ {
+#if HAVE_LIBMEMCACHED_MEMCACHED_H
+ c->mc_st = memcached(val, strlen(val));
+ if (!c->mc_st)
+ {
+ ZOOM_set_error(c, ZOOM_ERROR_MEMCACHED, val);
+ return;
+ }
+#else
+ ZOOM_set_error(c, ZOOM_ERROR_MEMCACHED, "not enabled");
+ return;
+#endif
+ }
+
if (c->sru_mode == zoom_sru_error)
{
ZOOM_set_error(c, ZOOM_ERROR_UNSUPPORTED_PROTOCOL, val);
if (!c)
return;
yaz_log(c->log_api, "%p ZOOM_connection_destroy", c);
+
+#if HAVE_LIBMEMCACHED_MEMCACHED_H
+ if (c->mc_st)
+ memcached_free(c->mc_st);
+#endif
if (c->cs)
cs_close(c->cs);
}
#endif
resultset_use(1);
+ r->mc_key = 0;
return r;
}
ZOOM_connection_search(ZOOM_connection c, ZOOM_query q)
{
ZOOM_resultset r = ZOOM_resultset_create();
- ZOOM_task task;
const char *cp;
+ ZOOM_task task;
int start, count;
const char *syntax, *elementSetName, *schema;
-
yaz_log(c->log_api, "%p ZOOM_connection_search set %p query %p", c, r, q);
r->r_sort_spec = ZOOM_query_get_sortspec(q);
r->query = q;
r->connection = c;
r->next = c->resultsets;
c->resultsets = r;
+
+#if HAVE_LIBMEMCACHED_MEMCACHED_H
+ r->mc_key = wrbuf_alloc();
+ wrbuf_puts(r->mc_key, c->host_port);
+ wrbuf_puts(r->mc_key, ";");
+ wrbuf_puts(r->mc_key, ZOOM_query_get_query_string(q));
+ if (c->mc_st)
+ {
+ size_t v_len;
+ uint32_t flags;
+ memcached_return_t rc;
+ char *v = memcached_get(c->mc_st, wrbuf_buf(r->mc_key),
+ wrbuf_len(r->mc_key), &v_len, &flags, &rc);
+ if (v)
+ {
+ yaz_log(YLOG_LOG, "For key %s got value %.*s",
+ wrbuf_cstr(r->mc_key), (int) v_len, v);
+ }
+ else
+ {
+ yaz_log(YLOG_LOG, "For key %s got NO value", wrbuf_cstr(r->mc_key));
+ }
+ }
+#endif
+
if (c->host_port && c->proto == PROTO_HTTP)
{
if (!c->cs)
#if SHPTR
YAZ_SHPTR_DEC(r->record_wrbuf, wrbuf_destroy);
#endif
+ wrbuf_destroy(r->mc_key);
resultset_use(-1);
xfree(r);
}
return "Extended Service. invalid version";
case ZOOM_ERROR_ES_INVALID_SYNTAX:
return "Extended Service. invalid syntax";
+ case ZOOM_ERROR_MEMCACHED:
+ return "Memcached";
default:
return diagbib1_str(error);
}
handle_facet_result(c, resultset, sr->additionalSearchInfo);
resultset->size = *sr->resultCount;
+
+#if HAVE_LIBMEMCACHED_MEMCACHED_H
+ if (c->mc_st)
+ {
+ uint32_t flags = 0;
+ memcached_return_t rc;
+ time_t expiration = 36000;
+ char str[40];
+
+ sprintf(str, ODR_INT_PRINTF, *sr->resultCount);
+ rc = memcached_set(c->mc_st,
+ wrbuf_buf(resultset->mc_key),wrbuf_len(resultset->mc_key),
+ str, strlen(str), expiration, flags);
+ yaz_log(YLOG_LOG, "Key=%s value=%s rc=%u %s",
+ wrbuf_cstr(resultset->mc_key), str, (unsigned) rc,
+ memcached_last_error_message(c->mc_st));
+ }
+#endif
handle_Z3950_records(c, sr->records, 0);
}