             }
         }
     }
+
+    private func substractSize(size : UInt64) {
+        if (self.size > size) {
+            self.size -= size
+        } else {
+            Log.error("Disk cache size (\(self.size)) is smaller than size to substract (\(size))")
+            self.size = 0
+        }
+    }
 }
 
 private func isNoSuchFileError(error : NSError?) -> Bool {

            let fileSize = attributes.fileSize()
            do {
                try fileManager.removeItemAtPath(path)
                self.size -= fileSize
            } catch {
                Log.error("Failed to remove file", error as NSError)
            }

        }
        
        if let attributes = previousAttributes {
            substractSize(attributes.fileSize())
        }
        self.size += UInt64(data.length)
        self.controlCapacity()
