Liking cljdoc? Tell your friends :D


Clojure function memoization using Caffeine java library.

Clojars Project

Design goals

  • Use Caffeine for function memoization with all benefits provided by Caffeine.

Basic usage

(ns user.readme-usage
  (:require [strojure.caffeine-memoize.core :as memoize]))

(defn f*
  "Original function to memoize."
  (println 'f* [x] (System/currentTimeMillis))
  (Thread/sleep 100)
  (str "test " [x]))

(def f
  "Memoized function expiring in 60 seconds."
  (memoize/memoize #'f* first "expireAfterWrite=60s"))

  ;;; Invoke memoized function.
  (f 10)                                          ; Execution time mean : 83,530604 ns
  ;f* [10] 1654088424755
  #_"test [10]"

  ;;; Clear cache for x=10.
  (memoize/clear! f [10])

  ;;; Clear all cached values.
  (memoize/clear! f)

  ;;; Put custom value for x=10.
  (memoize/put! f [10] ::manual)
  (f 10)

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close