                 imageRequest.progress = nil
                 self.activeRequests.remove(at: self.activeRequests.index(of: imageRequest)!)
                 if let imageData = imageData {
-                  self.saveImageToDatabase(imageData, forURLString: imageRequest.URLString)
+                  self.saveImageToDatabase(imageData, forURLString: imageRequest.URLString, expiresAfter: self.configuration.expireImagesAfter)
                 }
                 
                 // call completion blocks

  
  private func removeExpiredImages() {
    DispatchQueue.main.async(execute: {() -> Void in
      var imageDeleteKeys = [String]()
      var imageAttributeDeleteKeys = [String]()
      self.attributesDatabaseConnection.read({ transaction in
        
        transaction.enumerateKeysAndMetadata(inCollection: YapImageManagerImageAttributesCollection, using: { (key: String, metadata: Any?, stop: UnsafeMutablePointer<ObjCBool>) in
          if let created = metadata as? NSDate {
            let timeSince: TimeInterval = -created.timeIntervalSinceNow
            if timeSince > self.configuration.expireImagesAfter {
              DDLogVerbose("Remove expired image \(key)")
              imageDeleteKeys.append(key)
            }
            if timeSince > self.configuration.expireImageAttributesAfter {
              DDLogVerbose("Remove expired attributes \(key)")
              imageAttributeDeleteKeys.append(key)
            }
          }
        })
        
        // remove expired images and images, images first so you never end up with images without attributes
        self.backgroundDatabaseConnection.asyncReadWrite({ transaction  in
          // remove images
          transaction.removeObjects(forKeys: imageDeleteKeys, inCollection: YapImageManagerImageCollection)
        }, completionBlock: {() -> Void in
          // remove image attributes after removing images has completed
          self.backgroundAttributesDatabaseConnection.asyncReadWrite( { transaction in
            transaction.removeObjects(forKeys: imageAttributeDeleteKeys, inCollection: YapImageManagerImageAttributesCollection)
          }, completionBlock: {() -> Void in
            // DEBUG
            //[self validateDatabaseIntegrity];
          })
        })
        // DEBUG
        //[self validateDatabaseIntegrity];
      })
    })
  }
  

              // write the image attributes, if necessary
              if shouldUpdateImageAttributes {
                DDLogVerbose("Update image attributes \(imageRequest.URLString)")
                self.updateImageAttributes(with: imageSize, forURLString: imageRequest.URLString, expiresAfter: self.configuration.expireImageAttributesAfter)
              }
              
              // decode all images and save to cache
