diff --git a/app/Main.hs b/app/Main.hs
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -194,7 +194,7 @@
   statsdAggregates <-
     env "STATSD_AGGREGATES" False parseBool
   statsdPrefix <-
-    getStatsdPrefix
+    env "STATSD_PREFIX" "haskoin_store" pure
   tickerRefresh <-
     env "TICKER_REFRESH" (90 * 1000 * 1000) readMaybe
   tickerURL <-
@@ -235,17 +235,6 @@
       txTimeout <-
         env "TX_TIMEOUT" d.txTimeout readMaybe
       return WebLimits {..}
-    getStatsdPrefix = do
-      let go = prefix <|> nomad
-          prefix =
-            MaybeT $ lookupEnv "STATSD_PREFIX"
-          nomad = do
-            task <-
-              MaybeT $ lookupEnv "NOMAD_TASK_NAME"
-            service <-
-              MaybeT $ lookupEnv "NOMAD_ALLOC_INDEX"
-            return $ "app." <> task <> "." <> service
-      fromMaybe "haskoin_store" <$> runMaybeT go
 
 netNames :: String
 netNames = intercalate "|" $ map (.name) allNets
diff --git a/haskoin-store.cabal b/haskoin-store.cabal
--- a/haskoin-store.cabal
+++ b/haskoin-store.cabal
@@ -5,7 +5,7 @@
 -- see: https://github.com/sol/hpack
 
 name:           haskoin-store
-version:        1.5.2
+version:        1.5.4
 synopsis:       Storage and index for Bitcoin and Bitcoin Cash
 description:    Please see the README on GitHub at <https://github.com/haskoin/haskoin-store#readme>
 category:       Bitcoin, Finance, Network
diff --git a/src/Haskoin/Store/Cache.hs b/src/Haskoin/Store/Cache.hs
--- a/src/Haskoin/Store/Cache.hs
+++ b/src/Haskoin/Store/Cache.hs
@@ -772,14 +772,14 @@
       refreshLock
 
 pruneDB ::
-  (MonadLoggerIO m, StoreReadBase m) => CacheX m ()
+  (MonadUnliftIO m, MonadLoggerIO m, StoreReadBase m) => CacheX m ()
 pruneDB = do
   x <- asks (.maxKeys)
   s <- runRedis Redis.dbsize
   $(logDebugS) "Cache" "Pruning old xpubs"
-  when (s > x) $
+  when (s > x) . void . withLock $
     void . delXPubKeys . map fst
-      =<< runRedis (getFromSortedSet maxKey Nothing 0 32)
+      =<< runRedis (getFromSortedSet maxKey Nothing 0 (fromIntegral (s - x)))
 
 touchKeys :: (MonadLoggerIO m) => [XPubSpec] -> CacheX m ()
 touchKeys xpubs = do
@@ -797,14 +797,17 @@
   CacheX m ()
 cacheWriterReact CacheNewBlock = do
   $(logDebugS) "Cache" "Received new block event"
+  pruneDB
   newBlockC
   syncMempoolC
 cacheWriterReact (CacheNewTx txid) = do
   $(logDebugS) "Cache" $
     "Received new transaction event: " <> txHashToHex txid
+  pruneDB
   syncNewTxC [txid]
 cacheWriterReact (CacheSyncMempool l) = do
   $(logDebugS) "Cache" "Received sync mempool event"
+  pruneDB
   newBlockC
   syncMempoolC
   atomically $ l ()
@@ -857,11 +860,7 @@
     should_index =
       asks (.minAddrs) >>= \x ->
         if x <= lenNotNull xbals
-          then
-            inSync >>= \s ->
-              if s
-                then pruneDB >> return True
-                else return False
+          then inSync
           else return False
     key = idxPfx <> encode xpub
     opts =
