about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libstore/store-api.cc1
-rw-r--r--src/libstore/store-api.hh7
-rw-r--r--src/libutil/lru-cache.hh8
-rw-r--r--src/libutil/sync.hh1
-rw-r--r--src/nix-daemon/nix-daemon.cc5
5 files changed, 17 insertions, 5 deletions
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index 441166d04d8f..59348c5d0b5f 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -242,6 +242,7 @@ Path Store::computeStorePathForText(const string & name, const string & s,
 
 Store::Store(const Params & params)
     : storeDir(get(params, "store", settings.nixStore))
+    , state({std::stoi(get(params, "path-info-cache-size", "65536"))})
 {
 }
 
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index 98f2803f8136..f58dbde350c7 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -241,7 +241,7 @@ protected:
 
     struct State
     {
-        LRUCache<std::string, std::shared_ptr<ValidPathInfo>> pathInfoCache{64 * 1024};
+        LRUCache<std::string, std::shared_ptr<ValidPathInfo>> pathInfoCache;
     };
 
     Sync<State> state;
@@ -252,6 +252,11 @@ protected:
 
 public:
 
+    size_t getCacheSize()
+    {
+        return state.lock()->pathInfoCache.size();
+    }
+
     virtual ~Store() { }
 
     virtual std::string getUri() = 0;
diff --git a/src/libutil/lru-cache.hh b/src/libutil/lru-cache.hh
index 35983aa2c918..3cb5d50889d9 100644
--- a/src/libutil/lru-cache.hh
+++ b/src/libutil/lru-cache.hh
@@ -11,7 +11,7 @@ class LRUCache
 {
 private:
 
-    size_t maxSize;
+    size_t capacity;
 
     // Stupid wrapper to get around circular dependency between Data
     // and LRU.
@@ -27,14 +27,16 @@ private:
 
 public:
 
-    LRUCache(size_t maxSize) : maxSize(maxSize) { }
+    LRUCache(size_t capacity) : capacity(capacity) { }
 
     /* Insert or upsert an item in the cache. */
     void upsert(const Key & key, const Value & value)
     {
+        if (capacity == 0) return;
+
         erase(key);
 
-        if (data.size() >= maxSize) {
+        if (data.size() >= capacity) {
             /* Retire the oldest item. */
             auto oldest = lru.begin();
             data.erase(*oldest);
diff --git a/src/libutil/sync.hh b/src/libutil/sync.hh
index 2aa074299b23..611c900e0a32 100644
--- a/src/libutil/sync.hh
+++ b/src/libutil/sync.hh
@@ -33,6 +33,7 @@ public:
 
     Sync() { }
     Sync(const T & data) : data(data) { }
+    Sync(T && data) noexcept : data(std::move(data)) { }
 
     class Lock
     {
diff --git a/src/nix-daemon/nix-daemon.cc b/src/nix-daemon/nix-daemon.cc
index ab5826b0d1a7..b6a46642c7c1 100644
--- a/src/nix-daemon/nix-daemon.cc
+++ b/src/nix-daemon/nix-daemon.cc
@@ -637,7 +637,10 @@ static void processConnection(bool trusted)
 #endif
 
         /* Open the store. */
-        auto store = make_ref<LocalStore>(Store::Params()); // FIXME: get params from somewhere
+        Store::Params params; // FIXME: get params from somewhere
+        // Disable caching since the client already does that.
+        params["path-info-cache-size"] = "0";
+        auto store = make_ref<LocalStore>(params);
 
         stopWork();
         to.flush();