ZOOM: initial experiments with memcached
[yaz-moved-to-github.git] / src / zoom-z3950.c
index 69d6dbe..a16a809 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2013 Index Data
+ * Copyright (C) Index Data
  * See the file LICENSE for details.
  */
 /**
@@ -778,15 +778,6 @@ zoom_ret ZOOM_connection_Z3950_send_search(ZOOM_connection c)
                result sets on the server. */
             for (ord = 1; ; ord++)
             {
-#if ZOOM_RESULT_LISTS
-                ZOOM_resultsets rsp;
-                sprintf(setname, "%d", ord);
-                for (rsp = c->resultsets; rsp; rsp = rsp->next)
-                    if (rsp->resultset->setname && !strcmp(rsp->resultset->setname, setname))
-                        break;
-                if (!rsp)
-                    break;
-#else
                 ZOOM_resultset rp;
                 sprintf(setname, "%d", ord);
                 for (rp = c->resultsets; rp; rp = rp->next)
@@ -794,8 +785,6 @@ zoom_ret ZOOM_connection_Z3950_send_search(ZOOM_connection c)
                         break;
                 if (!rp)
                     break;
-#endif
-
             }
             r->setname = xstrdup(setname);
             yaz_log(c->log_details, "%p ZOOM_connection_send_search: "
@@ -1284,6 +1273,24 @@ static void handle_Z3950_search_response(ZOOM_connection c,
     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);
 }
 
@@ -1397,6 +1404,7 @@ static void handle_Z3950_records(ZOOM_connection c, Z_Records *sr,
                         "ZOOM C generated. Present phase and no records");
                 ZOOM_record_cache_add(resultset, myrec, *start,
                                       syntax, elementSetName, schema, 0);
+                *count = 0;
             }
         }
         else if (present_phase)
@@ -1409,6 +1417,7 @@ static void handle_Z3950_records(ZOOM_connection c, Z_Records *sr,
                     "ZOOM C generated: Present response and no records");
             ZOOM_record_cache_add(resultset, myrec, *start,
                                   syntax, elementSetName, schema, 0);
+            *count = 0;
         }
     }
 }