Name: expiring-map
Owner: luminus-framework
Description: a thread-safe map that expires entries
Created: 2015-09-11 03:24:58.0
Updated: 2017-09-09 10:30:34.0
Pushed: 2017-03-30 15:16:26.0
Homepage: null
Size: 21
Language: Clojure
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
A Clojure wrapper for the expiringmap. The expiring-map is a thread-safe mutable map that supports expiry for elements.
The expiry map responds to the standard collection functions such as
get
, count
, keys
, vals
, and empty?
.
In addition, the map provides the following functions for mutating its values:
assoc!
- associates a key value pair with the mapdissoc!
- dissociates a key from the mapclear!
- removes all key/value pairs from the mapreset-expiration!
- resets the expirating timeout for the given keyuire '[expiring-map.core :as em])
cache (em/expiring-map 10))
assoc! cache :foo "bar")
cache :bar)
cache :foo)
cache :bar "defualt")
nt cache)
s cache)
s cache)
ty? cache)
dissoc! cache :foo)
assoc! cache :foo "foo" :bar "bar")
reset-expiration! cache :foo)
clear! cache)
The time unit defaults to :seconds
, the following time units are supported:
:nanoseconds
:microseconds
:milliseconds
:seconds
:minutes
:hours
:day
e.g:
expiring-map 10 {:time-unit :minutes})
The expiration policy can either be set to creation time or last access, defaults to creation time.
cache (em/expiring-map
10
{:expiration-policy :access
:time-unit :minutes}))
The map allows setting expiry listeners, a listener must be a function that accepts the key and the value that expires:
cache (em/expiring-map
10
{:listeners [(fn [k v] (println "Expired:" k v))]}))
The benchmarks below test the assoc/dissoc cycle for the expiring-map, regular atom, and core.cache atom.
ING: Final GC required 409.9942905040538 % of runtime
uation count : 4756014 in 6 samples of 792669 calls.
Execution time mean : 120.809576 ns
Execution time std-deviation : 2.684070 ns
xecution time lower quantile : 118.923613 ns ( 2.5%)
xecution time upper quantile : 124.374281 ns (97.5%)
Overhead used : 1.988494 ns
ING: Final GC required 481.8947027815336 % of runtime
uation count : 1893510 in 6 samples of 315585 calls.
Execution time mean : 322.901037 ns
Execution time std-deviation : 11.538941 ns
xecution time lower quantile : 313.718453 ns ( 2.5%)
xecution time upper quantile : 340.737836 ns (97.5%)
Overhead used : 1.988494 ns
d 1 outliers in 6 samples (16.6667 %)
low-severe 1 (16.6667 %)
iance from outliers : 13.8889 % Variance is moderately inflated by outliers
ING: Final GC required 398.9148954873636 % of runtime
uation count : 925734 in 6 samples of 154289 calls.
Execution time mean : 645.750787 ns
Execution time std-deviation : 19.287433 ns
xecution time lower quantile : 625.196819 ns ( 2.5%)
xecution time upper quantile : 666.538213 ns (97.5%)
Overhead used : 1.988494 ns
Copyright © 2015 Dmitri Sotnikov
Distributed under the Apache 2.0 license