+void RecordCache::add(ODR o, Z_NamePlusRecordList *npr, int start,
+ int hits)
+{
+ // Build appropriate compspec for this response
+ Z_RecordComposition *comp = 0;
+ if (hits == -1 && m_p->presentRequest)
+ comp = m_p->presentRequest->recordComposition;
+ else if (hits > 0 && m_p->searchRequest)
+ {
+ Z_ElementSetNames *esn;
+
+ if (hits <= *m_p->searchRequest->smallSetUpperBound)
+ esn = m_p->searchRequest->smallSetElementSetNames;
+ else
+ esn = m_p->searchRequest->mediumSetElementSetNames;
+ comp = (Z_RecordComposition *) nmem_malloc(m_p->nmem, sizeof(*comp));
+ comp->which = Z_RecordComp_simple;
+ comp->u.simple = esn;
+ }
+ add(o, npr, start, comp);
+}
+
+int RecordCache::Rep::match(RecordCache_Entry *entry,
+ Odr_oid *syntax, int offset,
+ Z_RecordComposition *comp)
+{
+ // See if our compspec match...
+ int match = 0;
+ ODR o1 = odr_createmem(ODR_ENCODE);
+ ODR o2 = odr_createmem(ODR_ENCODE);
+
+ z_RecordComposition(o1, &comp, 1, 0);
+ z_RecordComposition(o2, &entry->m_comp, 1, 0);
+
+ int len1 = -1;
+ char *buf1 = odr_getbuf(o1, &len1, 0);
+ int len2 = -1;
+ char *buf2 = odr_getbuf(o2, &len2, 0);
+
+ if (buf1 && buf2 && len1 && len1 == len2 && !memcmp(buf1, buf2, len1))
+ match = 1;
+ else if (!buf1 && !buf2 && !len1 && !len2)
+ match = 1;
+
+ odr_destroy(o1);
+ odr_destroy(o2);
+ if (!match)
+ return 0;
+ if (!syntax)
+ return 0;
+ // See if offset, OID match..
+ if (entry->m_offset == offset &&
+ entry->m_record->which == Z_NamePlusRecord_databaseRecord &&
+ !oid_oidcmp(entry->m_record->u.databaseRecord->direct_reference,
+ syntax))
+ return 1;
+#if 0
+ char mstr1[100];
+ oid_to_dotstring(entry->m_record->u.databaseRecord->direct_reference, mstr1);
+ char mstr2[100];
+ oid_to_dotstring(syntax, mstr2);
+ yaz_log(YLOG_LOG, "match fail 3 d=%s s=%s", mstr1, mstr2);
+#endif
+
+ return 0;
+}
+
+int RecordCache::lookup(ODR o, Z_NamePlusRecordList **npr,
+ int start, int num,
+ Odr_oid *syntax,
+ Z_RecordComposition *comp)