forked from willcohen/cloffeine
-
Notifications
You must be signed in to change notification settings - Fork 4
/
async_loading_cache.clj
37 lines (31 loc) · 1.12 KB
/
async_loading_cache.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(ns cloffeine.async-loading-cache
(:refer-clojure :exclude [get])
(:require [cloffeine.common :as common]
[cloffeine.async-cache :as acache]
[cloffeine.loading-cache :as loading-cache])
(:import [com.github.benmanes.caffeine.cache AsyncCache AsyncLoadingCache CacheLoader AsyncCacheLoader]))
(defn make-cache
(^AsyncLoadingCache [^CacheLoader cl]
(make-cache cl {}))
(^AsyncLoadingCache [^CacheLoader cl settings]
(let [bldr (common/make-builder settings)]
(.buildAsync bldr cl))))
(defn make-cache-async-loader
(^AsyncLoadingCache [^AsyncCacheLoader cl]
(make-cache cl {}))
(^AsyncLoadingCache [^AsyncCacheLoader cl settings]
(let [bldr (common/make-builder settings)]
(.buildAsync bldr cl))))
(defn get
([^AsyncLoadingCache alcache k]
(.get alcache k))
([^AsyncCache alcache k f]
(acache/get alcache k f)))
(def get-if-present acache/get-if-present)
(def put! acache/put!)
(defn ->LoadingCache [^AsyncLoadingCache alcache]
(.synchronous alcache))
(defn invalidate! [^AsyncLoadingCache alcache k]
(-> alcache
->LoadingCache
(loading-cache/invalidate! k)))