         return
       return
 
-    _fetchAndCache = ->
+    _fetchAndCache = {}
+    _fetchAndCache.ga = ->
       ga.authPromise.then ga.fetch key # .then transform
         .then (data) ->
           db.set key, JSON.stringify data
+          # delete key at start of next day in case there's a midnight refresh
+          db.expireat key, moment().add('days', 1).startOf('day').unix()
           resolve data
           return
         .catch (err) -> console.error "[ERROR] ", err; return
       return
-
-    _fetchAndCacheOverview = ->
+    _fetchAndCache.overview = ->
       request {url: 'https://bower.herokuapp.com/packages', json: true}, (err, res, body) ->
         if err
           error = new Error "[ERROR] can't fetch package count from bower registry, err = #{ err }"

        else
          data = totalPkgs: body.length
          db.set key, JSON.stringify data
          resolve data
        return


redis = require 'redis'
rsvp = require 'rsvp'
request = require 'request'
moment = require 'moment'

# Custom
ga = require './ga'
