HTRACE-332. htraced: optionally enable leveldb LRU cache (cmccabe)
diff --git a/htrace-htraced/go/src/org/apache/htrace/conf/config_keys.go b/htrace-htraced/go/src/org/apache/htrace/conf/config_keys.go
index 9f3bc61..16790d8 100644
--- a/htrace-htraced/go/src/org/apache/htrace/conf/config_keys.go
+++ b/htrace-htraced/go/src/org/apache/htrace/conf/config_keys.go
@@ -100,6 +100,9 @@
 // MB in leveldb 1.16.  See leveldb's options.h for more details.
 const HTRACE_LEVELDB_WRITE_BUFFER_SIZE = "leveldb.write.buffer.size"
 
+// The LRU cache size for leveldb, in bytes.
+const HTRACE_LEVELDB_CACHE_SIZE = "leveldb.cache.size"
+
 // Default values for HTrace configuration keys.
 var DEFAULTS = map[string]string{
 	HTRACE_WEB_ADDRESS:  fmt.Sprintf("0.0.0.0:%d", HTRACE_WEB_ADDRESS_DEFAULT_PORT),
@@ -117,6 +120,7 @@
 	HTRACE_NUM_HRPC_HANDLERS:             "20",
 	HTRACE_HRPC_IO_TIMEOUT_MS:            "60000",
 	HTRACE_LEVELDB_WRITE_BUFFER_SIZE:     "0",
+	HTRACE_LEVELDB_CACHE_SIZE:            fmt.Sprintf("%d", 100 * 1024 * 1024),
 }
 
 // Values to be used when creating test configurations
diff --git a/htrace-htraced/go/src/org/apache/htrace/htraced/loader.go b/htrace-htraced/go/src/org/apache/htrace/htraced/loader.go
index cb5ada7..5914004 100644
--- a/htrace-htraced/go/src/org/apache/htrace/htraced/loader.go
+++ b/htrace-htraced/go/src/org/apache/htrace/htraced/loader.go
@@ -115,6 +115,8 @@
 		}
 	}
 	dld.openOpts = levigo.NewOptions()
+	cacheSize := cnf.GetInt(conf.HTRACE_LEVELDB_CACHE_SIZE)
+	dld.openOpts.SetCache(levigo.NewLRUCache(cacheSize))
 	dld.openOpts.SetParanoidChecks(false)
 	writeBufferSize := cnf.GetInt(conf.HTRACE_LEVELDB_WRITE_BUFFER_SIZE)
 	if writeBufferSize > 0 {