       (j/execute! db (cons (new-history-sql) records) :multi? true :transaction? false))
     (catch java.sql.SQLException e (j/print-sql-exception-chain e))))
 
+(defn- delete-history-sql []
+  (str "DELETE FROM " (qualified-history)
+       " WHERE ARRAY[version] <@ ?"))
+
+(defn- delete-history [db features]
+  (try
+    (let [records (map (juxt :_all_versions) features)]
+      (j/execute! db (cons (delete-history-sql) records) :multi? true :transaction? false))
+    (catch java.sql.SQLException e (j/print-sql-exception-chain e))))
+
 (defn- feature-key [feature]
   [(:dataset feature) (:collection feature) (:id feature)])
 
-(defn- flush-all [db new-current-batch delete-current-batch new-history-batch]
+(defn- flush-all [db new-current-batch delete-current-batch new-history-batch delete-history-batch]
   "Used for flushing all batches, so update current is always performed after new current"
   (flush-batch new-current-batch (partial new-current db))
   (flush-batch delete-current-batch (partial delete-current db))
-  (flush-batch new-history-batch (partial new-history db)))
+  (flush-batch new-history-batch (partial new-history db))
+  (flush-batch delete-history-batch (partial delete-history db)))
 
 (defn- cache-store-key [f]
   [(:_dataset f) (:_collection f) (:_id f)])
 
 (defn- cache-value [_ f] f)
+
+(defn- cache-invalidate [_ f])
 
 (defn- cache-use-key [dataset collection id]
   [dataset collection id])

  (proj/close-feature [_ feature]
    (proj/new-feature _ feature))
  (proj/delete-feature [_ feature]
    nil)
  (proj/close [this]
    (flush-all db new-current-batch delete-current-batch new-history-batch)
    this)
  )


  (str "DELETE FROM " (qualified-current)
       " WHERE version = ?"))

(defn- delete-current [db versions]
  (try
    (let [records (map #(vector %) versions)]
      (j/execute! db (cons (delete-current-sql) records) :multi? true :transaction? false))
    (catch java.sql.SQLException e (j/print-sql-exception-chain e))))

