* Copyright (c) 2002-2003, Index Data.
* See the file LICENSE for details.
*
- * $Id: yaz-z-cache.cpp,v 1.4 2003-08-28 18:46:54 adam Exp $
+ * $Id: yaz-z-cache.cpp,v 1.7 2003-10-10 17:58:30 adam Exp $
*/
#include <yaz/log.h>
m_entries = 0;
m_presentRequest = 0;
m_searchRequest = 0;
+ m_max_size = 200000;
}
Yaz_RecordCache::~Yaz_RecordCache ()
nmem_destroy(m_mem);
}
+void Yaz_RecordCache::set_max_size(int sz)
+{
+ m_max_size = sz;
+}
+
void Yaz_RecordCache::clear ()
{
nmem_destroy(m_mem);
void Yaz_RecordCache::add (ODR o, Z_NamePlusRecordList *npr, int start,
int hits)
{
+ if (nmem_total(m_mem) > m_max_size)
+ {
+ yaz_log(LOG_LOG, "cache size");
+ return;
+ }
// Build appropriate compspec for this response
Z_RecordComposition *comp = 0;
if (hits == -1 && m_presentRequest)
{
Yaz_RecordCache_Entry *entry = (Yaz_RecordCache_Entry *)
nmem_malloc(m_mem, sizeof(*entry));
- entry->m_record = npr->records[i];
+ entry->m_record = (Z_NamePlusRecord *)
+ nmem_malloc(m_mem, sizeof(*entry->m_record));
+ entry->m_record->databaseName = npr->records[i]->databaseName;
+ entry->m_record->which = npr->records[i]->which;
+ entry->m_record->u.databaseRecord = npr->records[i]->u.databaseRecord;
entry->m_comp = comp;
entry->m_offset = i + start;
entry->m_next = m_entries;
odr_destroy(o2);
if (!match)
return 0;
-
if (!syntax)
return 0;
// See if offset, OID match..
!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(LOG_LOG, "match fail 3 d=%s s=%s", mstr1, mstr2);
+#endif
+
return 0;
}
Z_RecordComposition *comp)
{
int i;
- yaz_log(LOG_LOG, "cache lookup start=%d num=%d", start, num);
+ yaz_log(LOG_DEBUG, "cache lookup start=%d num=%d", start, num);
for (i = 0; i<num; i++)
{
break;
if (!entry)
return 0;
- (*npr)->records[i] = entry->m_record;
+ (*npr)->records[i] = (Z_NamePlusRecord *)
+ odr_malloc(o, sizeof(Z_NamePlusRecord));
+ (*npr)->records[i]->databaseName = entry->m_record->databaseName;
+ (*npr)->records[i]->which = entry->m_record->which;
+ (*npr)->records[i]->u.databaseRecord =
+ entry->m_record->u.databaseRecord;
}
return 1;
}