           async.parallel [
             (fin) ->
               # Update the cached value.
-              client.set key, value.toString(), fin
+              client.set name, value.toString(), fin
 
             (fin) ->
               return fin() unless options.expire
 
               # If the cached value should be stored for a certain amount of
               # time, set the lock and expiration timer.
-              client.set "lock:#{key}", true, (err) ->
+              client.set "lock:#{name}", true, (err) ->
                 fin err if err
-                client.expire "lock:#{key}", options.expire, fin
+                client.expire "lock:#{name}", options.expire, fin
           ], (err) ->
             done err if err
 
             # Unset the lock process; the value has been updated.
-            client.del "lock-process:#{key}", done
+            client.del "lock-process:#{name}", done
     ], (err, results) ->
       # The update was successful if there was no error.
       fn err, results and not err



  unset: (fn) ->
    key = @key()
    @client().del key, "lock:#{key}", "lock-process:#{key}", (err, results) ->
      fn err, !!results


  get: (fn) ->
    @client().get @key(), fn


  set: (fn) ->
    client = @client()
    key = @key()
    options = @options

    # Try to update the cached value.
    async.waterfall [
      # Check if the cached value is locked (and therefore still valid).
      (done) ->
        client.exists "lock:#{key}", done

      # Check if there's a process already running to update the cache.
      (exists, done) ->
        if exists
          throw new CacheError 'The key is currently locked.'

        client.get "lock-process:#{key}", done

      (pid, done) ->
        # If there's an update process, check that it's still running.
        if pid and processIsRunning pid
          throw new CacheError 'A process is currently updating this key.'

        # Time to update the cache.
        # Set the process lock.
        client.set "lock-process:#{key}", process.pid

        # Run the provided method to generate the new value to cache.
        options.update.call options.context, (err, value) ->

class Cache extends Impromptu.Cacheable
  @Error: CacheError


  client: ->
    @impromptu.db.client()


  run: (fn) =>
    # If this process isn't being run in the background,
