项目作者: ninjakoala

项目描述 :
Clojure TTL cache with background refresh
高级语言: Clojure
项目地址: git://github.com/ninjakoala/ttlr.git
创建时间: 2014-11-05T15:06:55Z
项目社区:https://github.com/ninjakoala/ttlr

开源协议:Eclipse Public License 1.0

下载


Clojars Project Build Status

  1. (ns yourapp
  2. (:require [ninjakoala.ttlr :as ttlr]))
  3. (defn update-costly-thing
  4. []
  5. (Thread/sleep 10000)
  6. {:some "data"})
  7. (ttlr/init :cpu-count 1)
  8. ; Wait ten seconds after this next call (we're seeding the state with the result of (update-costly-thing))
  9. (ttlr/schedule :costly-thing update-costly-thing (* 60 1000) (update-costly-thing))
  10. ; Now retrieve your costly thing quickly and it'll be updated in the background every minute.
  11. (ttlr/state :costly-thing)

ttlr

TTL with refresh. You schedule refreshes to take place and store things under a particular :key-name.

Why not memoize or core.cache?

Because we wanted a way to be able to retrieve things in the background rather than have a user take the penalty of retrieving the item when the cache expires.

License

Copyright © 2014 Neil Prosser

Distributed under the Eclipse Public License either version 1.0 or (at
your option) any later version.