 
     #----------
 
+    _updateSessionTimerFor: (session,cb) ->
+        if @redis
+            # this will set the score, or update it if the session is
+            # already in the set
+            timeout_at = (Number(new Date) / 1000) + @_timeout_sec
+
+            @redis.zadd "session-timeouts", timeout_at, session, (err) =>
+                cb err
+
+        else
+            s = @_ensureMemorySession session
+
+            clearTimeout s.timeout if s.timeout
+
+            s.timeout = setTimeout =>
+                @_triggerSession session
+            , @_timeout_sec * 1000
+
+            cb null
+
+    #----------
+
+    _scrubSessionFor: (session,cb) ->
+        if @redis
+            @redis.zrem "session-timeouts", session, (err) =>
+                return cb err if err
+
+                @redis.del "duration-#{session}", (err) =>
+                    cb err
+
+        else
+           s = @_ensureMemorySession session
+           clearTimeout s.timeout if s.timeout
+           delete @sessions[session]
+
+           cb null
+
+
+    #----------
+
     _ensureMemorySession: (session) ->
-        @sessions[ session ] ||= duration:0, last_seen_at:Number(new Date())
+        @sessions[ session ] ||=
+            duration:0, last_seen_at:Number(new Date()), timeout:null
+
+    #----------
+
+    _triggerSession: (session) ->
+        @_scrubSessionFor session, (err) =>
+            return @log.error "Error cleaning session cache: #{err}" if err
+
+            @_finalizeSession session, (err,obj) =>
+                return @log.error "Error assembling session: #{err}" if err
+
+                if obj
+                    @_storeSession obj, (err) =>
+                        @log.error "Error writing session: #{err}" if err
 
     #----------
 

        #    console.log "last session is ", err, res

        # what sessions have we seen since then?

    #----------



        @log = @opts.log

        @_timeout_sec = Number(@opts.config.finalize_secs)

        if @opts.redis

            @redis = @opts.redis.client

        @es = new elasticsearch.Client
