         let moc = self.managedObjectContext
         let fm = self.fileManager
         moc.perform {
-            let groupTasks = self.permanentCacheTasks[groupKey] ?? [:]
-            for (_, task) in groupTasks {
-                task.cancel()
-            }
-            self.permanentCacheTasks.removeValue(forKey: groupKey)
+            self.permanentCacheCompletionManager.cancel(group: groupKey)
             guard let group = self.fetchCacheGroup(key: groupKey, moc: moc) else {
                 return
             }

                    DDLogError("Error moving cached file: \(error)")
                }
                moc.perform {
                    self.removePermanentCacheTask(groupKey: groupKey, key: key, variant: variant)
                    guard let item = self.fetchOrCreateCacheItem(key: key, variant: variant, moc: moc), let group = self.fetchOrCreateCacheGroup(key: groupKey, moc: moc) else {
                        failure(ImageControllerError.invalidImageCache)
                        return
                    }
                    group.addToCacheItems(item)
                    self.save(moc: moc)
                    success()
                }
            })
            task.priority = priority
            groupTasks[groupTaskKey] = task
            self.permanentCacheTasks[groupKey] = groupTasks
            task.resume()
        }
    }

        }
    }
    
    public func permanentlyCache(url: URL, groupKey: String, priority: Float = 0, failure: @escaping (Error) -> Void, success: @escaping () -> Void) {
        let key = self.cacheKeyForURL(url)
        let variant = self.variantForURL(url)
        let identifier = self.identifierForKey(key, variant: variant)
        let completion = ImageControllerPermanentCacheCompletion(success: success, failure: failure)
        guard permanentCacheCompletionManager.add(completion, forIdentifier: identifier) else {
            return
        }
        let moc = self.managedObjectContext
        moc.perform {
            if let item = self.fetchCacheItem(key: key, variant: variant, moc: moc) {
                if let group = self.fetchOrCreateCacheGroup(key: groupKey, moc: moc) {
                    group.addToCacheItems(item)
                }
                self.save(moc: moc)
                self.permanentCacheCompletionManager.complete(groupKey, identifier: identifier, enumerator: { (completion) in
                    completion.success()
                })
                return
            }
            let schemedURL = (url as NSURL).wmf_urlByPrependingSchemeIfSchemeless() as URL
            let task = self.session.downloadTask(with: schemedURL, completionHandler: { (fileURL, response, error) in
                guard let fileURL = fileURL, let response = response else {
                    let err = error ?? ImageControllerError.invalidResponse
                    self.permanentCacheCompletionManager.complete(groupKey, identifier: identifier, enumerator: { (completion) in
                        completion.failure(err)
                    })
                    return
                }
                let permanentCacheFileURL = self.permanentCacheFileURL(key: key, variant: variant)
