 (def ^:const metric-wait-time 60)
 (def ^:const cache-add-ttl 180)
 
-(defn agg-avg
+(defn- agg-avg
   [data]
   (/ (reduce + data) (count data)))
 
-(defn construct-mkey
+(defn- construct-mkey
   [tenant period rollup time]
   (str/join "-" [tenant period rollup time]))
 
-(defn construct-key
+(defn- construct-key
   ([tenant period rollup time path]
      (str/join "-" [(construct-mkey tenant period rollup time) path]))
   ([mkey path]
      (str/join "-" [mkey path])))
 
-(defn calc-delay
+(defn- calc-delay
   [rollup add]
   (+ rollup metric-wait-time add))
 
-(defn to-ms
+(defn- to-ms
   [sec]
   (* sec 1000))
 
-(defn create-flusher
+(defn- create-flusher
   [mkeys mkey pkeys tenant period rollup time ttl fn-get fn-agg fn-store fn-key]
   (fn []
     (try

                  (fn-flusher))]
    [delayer flusher]))

(defn set-pkeys!
  [mkeys tenant period rollup time ttl fn-get fn-agg fn-store fn-key]
  (let [mkey (construct-mkey tenant period rollup time)]
    (swap! mkeys

      (catch Exception e
        (info e "Cache flushing exception")))))

(defn- run-delayer!
  [rollup fn-flusher]
  (let [delayer (future
                  (Thread/sleep (to-ms (calc-delay rollup (rand-int 59)))))
