Skip to content

ithayer/cachana

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cachana makes it easy to memoize function calls in clojure to a thread-local cache or to a network-based cache (eg: memcache).


Examples:

  (defn my-inc [x]
    (println "Work done on: " x)
    (inc x))

  ;; thread-local 

  (with-local-cache
    ((memoize my-inc) 2)
    ((memoize my-inc) 2)) ;; cached
  
  ;; network-only 

  ((memoize {:mode :network} my-inc) 2)
  ((memoize {:mode :network} my-inc) 2) ;; cached

  ;; both

  (with-local-cache
    ((memoize {:mode :network} my-inc) 2)
    ((memoize {:mode :network} my-inc) 2)) ;; retrieved from local

  (with-local-cache
    ((memoize {:mode :network} my-inc) 2)  ;; retrieved from network
    ((memoize {:mode :network} my-inc) 2)) ;; retrieved from local

  ;; Specify cache bucket location.

  (with-local-cache
    ((memoize {:location [:cookies "two"]} my-inc) 2)
    ((memoize {:location [:cookies "two"]} my-inc) 2))

About

Caching and memoization for Clojure

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published