Extend comment about start facet parameter
[yaz-moved-to-github.git] / src / zoom-record-cache.c
index 17c4ac5..957e8f9 100644 (file)
@@ -128,40 +128,13 @@ void ZOOM_record_cache_add(ZOOM_resultset r, Z_NamePlusRecord *npr,
                            Z_SRW_diagnostic *diag)
 {
     record_cache_add(r, npr, pos, syntax, elementSetName, schema, diag);
-#if HAVE_LIBMEMCACHED_MEMCACHED_H
-    if (r->connection->mc_st &&
-        !diag && npr->which == Z_NamePlusRecord_databaseRecord &&
-        npr->u.databaseRecord->which == Z_External_octet)
-    {
-        WRBUF k = wrbuf_alloc();
-        uint32_t flags = 0;
-        memcached_return_t rc;
-        time_t expiration = 36000;
-
-        wrbuf_write(k, wrbuf_buf(r->mc_key), wrbuf_len(r->mc_key));
-        wrbuf_printf(k, ";%d;%s;%s;%s", pos,
-                     syntax ? syntax : "",
-                     elementSetName ? elementSetName : "",
-                     schema ? schema : "");
-        rc = memcached_set(r->connection->mc_st,
-                           wrbuf_buf(k),wrbuf_len(k),
-                           npr->u.databaseRecord->u.octet_aligned->buf,
-                           npr->u.databaseRecord->u.octet_aligned->len,
-                           expiration, flags);
-
-        yaz_log(YLOG_LOG, "Store record key=%s rc=%u %s",
-                wrbuf_cstr(k), (unsigned) rc,
-                memcached_last_error_message(r->connection->mc_st));
-        wrbuf_destroy(k);
-    }
-#endif
+    ZOOM_memcached_add(r, npr, pos, syntax, elementSetName, schema, diag);
 }
 
-
-ZOOM_record ZOOM_record_cache_lookup(ZOOM_resultset r, int pos,
-                                     const char *syntax,
-                                     const char *elementSetName,
-                                     const char *schema)
+ZOOM_record ZOOM_record_cache_lookup_i(ZOOM_resultset r, int pos,
+                                       const char *syntax,
+                                       const char *elementSetName,
+                                       const char *schema)
 {
     ZOOM_record_cache rc;
 
@@ -178,51 +151,27 @@ ZOOM_record ZOOM_record_cache_lookup(ZOOM_resultset r, int pos,
             return &rc->rec;
         }
     }
-#if HAVE_LIBMEMCACHED_MEMCACHED_H
-    if (r->connection && r->connection->mc_st)
+    return 0;
+}
+
+ZOOM_record ZOOM_record_cache_lookup(ZOOM_resultset r, int pos,
+                                     const char *syntax,
+                                     const char *elementSetName,
+                                     const char *schema)
+{
+    Z_NamePlusRecord *npr;
+    ZOOM_record rec = ZOOM_record_cache_lookup_i(r, pos, syntax,
+                                                 elementSetName, schema);
+    if (rec)
     {
-        WRBUF k = wrbuf_alloc();
-        size_t v_len;
-        char *v;
-        uint32_t flags;
-        memcached_return_t rc;
-
-        wrbuf_write(k, wrbuf_buf(r->mc_key), wrbuf_len(r->mc_key));
-        wrbuf_printf(k, ";%d;%s;%s;%s", pos,
-                     syntax ? syntax : "",
-                     elementSetName ? elementSetName : "",
-                     schema ? schema : "");
-
-        v = memcached_get(r->connection->mc_st, wrbuf_buf(k), wrbuf_len(k),
-                          &v_len, &flags, &rc);
-        wrbuf_destroy(k);
-        if (v)
-        {
-            yaz_log(YLOG_LOG, "Building record from memcached!! syntax=%s",
-                syntax);
-            Z_NamePlusRecord *npr = (Z_NamePlusRecord *)
-                odr_malloc(r->odr, sizeof(Z_NamePlusRecord));
-            npr->databaseName = 0;
-            npr->which = Z_NamePlusRecord_databaseRecord;
-            npr->u.databaseRecord = (Z_External *)
-                odr_malloc(r->odr, sizeof(Z_External));
-            npr->u.databaseRecord->descriptor = 0;
-            npr->u.databaseRecord->direct_reference =
-                syntax ?
-                yaz_string_to_oid_odr(yaz_oid_std(), CLASS_RECSYN,
-                                      syntax, r->odr) : 0;
-            npr->u.databaseRecord->indirect_reference = 0;
-            npr->u.databaseRecord->which = Z_External_octet;
-            npr->u.databaseRecord->u.octet_aligned =
-                odr_create_Odr_oct(r->odr, v, v_len);
-            free(v);
-
-            if (v)
-                return record_cache_add(r, npr, pos, syntax, elementSetName,
-                                        schema, 0);
-        }
+        ZOOM_Event event = ZOOM_Event_create(ZOOM_EVENT_RECV_RECORD);
+        ZOOM_connection_put_event(r->connection, event);
+        return rec;
     }
-#endif
+    npr = ZOOM_memcached_lookup(r, pos, syntax, elementSetName, schema);
+    if (npr)
+        return record_cache_add(r, npr, pos, syntax, elementSetName,
+                                schema, 0);
     return 0;
 }