X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Fyaz-z-cache.cpp;h=dc58b25a0d8de581274c3326a49fee18f6603aba;hb=29d5f0cb70a5a61924e3b729f6ce5998cd6485ab;hp=8e521e6cd564894583c9b7cb15be70adf316c035;hpb=28588b9224eb5189af32b10f440ef2a917a05ea2;p=yazpp-moved-to-github.git diff --git a/src/yaz-z-cache.cpp b/src/yaz-z-cache.cpp index 8e521e6..dc58b25 100644 --- a/src/yaz-z-cache.cpp +++ b/src/yaz-z-cache.cpp @@ -1,12 +1,13 @@ /* - * Copyright (c) 2002-2003, Index Data. + * Copyright (c) 2002-2004, Index Data. * See the file LICENSE for details. * - * $Id: yaz-z-cache.cpp,v 1.5 2003-10-01 13:13:51 adam Exp $ + * $Id: yaz-z-cache.cpp,v 1.11 2004-12-13 20:50:54 adam Exp $ */ #include -#include +#include +#include struct Yaz_RecordCache_Entry { int m_offset; @@ -21,6 +22,7 @@ Yaz_RecordCache::Yaz_RecordCache () m_entries = 0; m_presentRequest = 0; m_searchRequest = 0; + m_max_size = 200000; } Yaz_RecordCache::~Yaz_RecordCache () @@ -28,6 +30,11 @@ 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); @@ -80,6 +87,8 @@ void Yaz_RecordCache::copy_presentRequest(Z_PresentRequest *pr) void Yaz_RecordCache::add (ODR o, Z_NamePlusRecordList *npr, int start, int hits) { + if (nmem_total(m_mem) > m_max_size) + return; // Build appropriate compspec for this response Z_RecordComposition *comp = 0; if (hits == -1 && m_presentRequest) @@ -108,7 +117,11 @@ void Yaz_RecordCache::add (ODR o, Z_NamePlusRecordList *npr, int start, { 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; @@ -142,7 +155,6 @@ int Yaz_RecordCache::match (Yaz_RecordCache_Entry *entry, odr_destroy(o2); if (!match) return 0; - if (!syntax) return 0; // See if offset, OID match.. @@ -151,6 +163,14 @@ int Yaz_RecordCache::match (Yaz_RecordCache_Entry *entry, !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; } @@ -160,7 +180,7 @@ int Yaz_RecordCache::lookup (ODR o, Z_NamePlusRecordList **npr, Z_RecordComposition *comp) { int i; - yaz_log(LOG_DEBUG, "cache lookup start=%d num=%d", start, num); + yaz_log(YLOG_DEBUG, "cache lookup start=%d num=%d", start, num); for (i = 0; irecords[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; }