Log request number. More configurable keepalive with pdu/bw limits.
[yazpp-moved-to-github.git] / src / yaz-z-cache.cpp
index 9706009..1468b7d 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 2002-2003, Index Data.
  * See the file LICENSE for details.
  * 
- * $Id: yaz-z-cache.cpp,v 1.2 2003-07-25 08:57:01 adam Exp $
+ * $Id: yaz-z-cache.cpp,v 1.6 2003-10-08 08:52:59 adam Exp $
  */
 
 #include <yaz/log.h>
@@ -21,6 +21,7 @@ Yaz_RecordCache::Yaz_RecordCache ()
     m_entries = 0;
     m_presentRequest = 0;
     m_searchRequest = 0;
+    m_max_size = 200000;
 }
 
 Yaz_RecordCache::~Yaz_RecordCache ()
@@ -28,6 +29,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 +86,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)
@@ -133,7 +141,6 @@ int Yaz_RecordCache::match (Yaz_RecordCache_Entry *entry,
     int len2 = -1;
     char *buf2 = odr_getbuf(o2, &len2, 0);
     
-    yaz_log(LOG_LOG, "buf1=%p buf2=%p len1=%d len2=%d", buf1, buf2, len1, len2);
     if (buf1 && buf2 && len1 && len1 == len2 && !memcmp(buf1, buf2, len1))
        match = 1;
     else if (!buf1 && !buf2 && !len1 && !len2)
@@ -144,6 +151,8 @@ int Yaz_RecordCache::match (Yaz_RecordCache_Entry *entry,
     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 &&
@@ -159,7 +168,7 @@ int Yaz_RecordCache::lookup (ODR o, Z_NamePlusRecordList **npr,
                             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++)
     {