title: How to cache images from listview from firebase swift 3
body: <p>I am struggling to comprehend how to cache images in my listview that I have fetched from Firebase. I have checked online and most of the solutions are somewhat different from the style of code I am writing so find it difficult to transfer over. Any solutions would be grateful for the class I have provided below.      </p>
  
  <pre><code>class StaffListTableViewCell: UITableViewCell {
  
      @IBOutlet weak var staffFirstAndLastName: UILabel!
  
      @IBOutlet weak var JobTitle: UILabel!
  
      @IBOutlet weak var staffImageView: UIImageView!
  
      var databaseRef: DatabaseReference {
          return Database.database().reference()
      }
  
      var storageRef: Storage {
          return Storage.storage()
      }
  
      override func awakeFromNib() {
          super.awakeFromNib()
          // Initialization code
      }
  
      func configureCell(teacher: StaffListsSTRUCT) {
  
  
          //this line of code helps sets the imageviews in the list view to nil before loading. 
          self.staffImageView.image = nil
  
          self.staffFirstAndLastName.text = teacher.staffName
          self.JobTitle.text = teacher.staffJobTitle
  
          let imageURL = teacher.staffImageViewString!
  
          self.storageRef.reference(forURL: imageURL).getData(maxSize: 1 * 1024 * 1024, completion: { (imgData,
              error) in
  
              if error == nil {
                  DispatchQueue.main.async {
                      if let data = imgData {
                          self.staffImageView.image = UIImage(data: data)
  
                      }
  
                  }
              } else {
  
                  print(error!.localizedDescription)
              }
  
          })
  
      }
  
  
  }
  </code></pre>