-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Break out schema and cache. Move gc to public API. (#716)
* Break out schema and cache. Move gc to public API. * Clear cache also on db deletion. * Cleanup. * Expose gc before_tx argument to C++. * Write cache initial schema as well. * Feedback for PR. * Use set spec. * Fix format.
- Loading branch information
Showing
12 changed files
with
253 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
(ns datahike.schema-cache | ||
(:require [clojure.core.cache.wrapped :as cw] | ||
[datahike.config :as dc] | ||
[datahike.store :as ds])) | ||
|
||
;; Shared schema read cache across all stores | ||
(def schema-meta-cache (cw/lru-cache-factory {} :threshold dc/*schema-meta-cache-size*)) | ||
|
||
;; LRU cache of LRU caches for write operations, one per store | ||
(def schema-write-caches | ||
(cw/lru-cache-factory {} :threshold dc/*schema-write-cache-max-db-count*)) | ||
|
||
(defn- get-or-create-write-cache [store-config] | ||
(let [store-id (ds/store-identity store-config)] | ||
(if (cw/has? schema-write-caches store-id) | ||
(cw/lookup schema-write-caches store-id) | ||
(let [new-cache (cw/lru-cache-factory {} :threshold dc/*schema-meta-cache-size*)] | ||
(cw/miss schema-write-caches store-id new-cache) | ||
new-cache)))) | ||
|
||
(defn cache-has? [schema-meta-key] | ||
(cw/has? schema-meta-cache schema-meta-key)) | ||
|
||
(defn cache-lookup [schema-meta-key] | ||
(cw/lookup schema-meta-cache schema-meta-key)) | ||
|
||
(defn cache-miss [schema-meta-key schema-meta] | ||
(cw/miss schema-meta-cache schema-meta-key schema-meta)) | ||
|
||
(defn write-cache-has? [store-config schema-meta-key] | ||
(let [write-cache (get-or-create-write-cache store-config)] | ||
(cw/has? write-cache schema-meta-key))) | ||
|
||
(defn add-to-write-cache [store-config schema-meta-key] | ||
(let [write-cache (get-or-create-write-cache store-config)] | ||
(cw/miss write-cache schema-meta-key true))) | ||
|
||
(defn clear-write-cache [store-config] | ||
(let [store-id (ds/store-identity store-config)] | ||
(cw/evict schema-write-caches store-id))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.