Haneke / HanekeSwift

A lightweight generic cache for iOS written in Swift with extra love for images.
Apache License 2.0
5.21k stars 591 forks source link

Failed to write key #371

Open HighmoreJx opened 8 years ago

HighmoreJx commented 8 years ago

[HANEKE][ERROR] Failed to write key fēng guāng-324 with error Error Domain=NSCocoaErrorDomain Code=4 "文件“fēng guāng-324”不存在。" UserInfo={NSFilePath=/var/mobile/Containers/Data/Application/30B773AF-7416-48B0-983F-DAFACF268D3B/Library/Caches/io.haneke/shared-strings/original/fēng guāng-3*24, NSUnderlyingError=0x15f4336a0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

greendog99 commented 7 years ago

I'm seeing the same thing, but here's some additional context. I was using HanekeSwift successfully in Swift 2.3, but when I updated my code to Swift 3.0.2 I started receiving the "Failed to write key" error. The error is below, with my actual key replaced with [mykey] and the simulator's NSFilePath shortened for readability:

[HANEKE][ERROR] Failed to write key [mykey] with error Error Domain=NSCocoaErrorDomain Code=4 "The folder “[mykey]” doesn’t exist." UserInfo={NSFilePath=[...]/Library/Caches/io.haneke/shared-json/original/[mykey], NSUserStringVariant=Folder, NSUnderlyingError=0x610000244ad0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

The NSFilePath above exists on my Mac (in the Simulator tree) only up to /Caches/io.haneke. There is no shared-json folder under it.

I'm fetching JSON data with:

let cache = Shared.JSONCache
let url = URL(string: "https://jsonplaceholder.typicode.com/posts")!
cache.fetch(URL: url).onSuccess { json in
   ...
}

I'm using Carthage, with this in my Cartfile: github "Haneke/HanekeSwift" "feature/swift-3"

I'll keep investigating, but hopefully this additional info will help tracking this down.

greendog99 commented 7 years ago

OK, I've determined that this only happens for me after I run Shared.JSONCache.removeAll(). That seems to match the problem reported in issue #245 (Failed to write key with error) so these two issues may be the same. The removeAll() was working fine in Swift 2.3.