https://github.com/ninjakoala/ttlr
Clojure TTL cache with background refresh
https://github.com/ninjakoala/ttlr
caching clojure
Last synced: 11 months ago
JSON representation
Clojure TTL cache with background refresh
- Host: GitHub
- URL: https://github.com/ninjakoala/ttlr
- Owner: ninjakoala
- License: epl-1.0
- Created: 2014-11-05T15:06:55.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2018-09-26T14:32:27.000Z (over 7 years ago)
- Last Synced: 2025-02-08T09:22:54.129Z (11 months ago)
- Topics: caching, clojure
- Language: Clojure
- Size: 10.7 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://clojars.org/com.ninjakoala/ttlr) [](https://travis-ci.org/ninjakoala/ttlr)
```clojure
(ns yourapp
(:require [ninjakoala.ttlr :as ttlr]))
(defn update-costly-thing
[]
(Thread/sleep 10000)
{:some "data"})
(ttlr/init :cpu-count 1)
; Wait ten seconds after this next call (we're seeding the state with the result of (update-costly-thing))
(ttlr/schedule :costly-thing update-costly-thing (* 60 1000) (update-costly-thing))
; Now retrieve your costly thing quickly and it'll be updated in the background every minute.
(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.