Closed ChristRm closed 8 years ago
When a new request for that cache item comes in, the dat of the item in the cache is checked. If it's too old it's ignored. The item is not removed from the cache. The item will not be thrown away because it will still be returned if there is no internet connection.
What is the best approach for cleaning cache? My app uses EVURLCach for caching web pages and I want to implement cleaning all pages that was cached earlier than for example 1-2 weeks. Is it right to remove all files from cache directory with creation date earlier than some date?
That would be a good approach. You could see the function cacheItemExpired in EVURLCache how you could implement something like that. You only have to add a mechanism to scan all files in a folder plus it's sub folders and set a default maxAge (in seconds)
Here is a short initial setup that you could use. If you have it working, then i think it would be nice if you could create a pull request for that.
open static func clearCacheOderThan(seconds: Double) {
// loop through all folders, subfolders, files and set storagePath
do {
let attributes = try FileManager.default.attributesOfItem(atPath: storagePath)
if let modDate: Date = attributes[FileAttributeKey.modificationDate] as? Date {
let modificationTimeSinceNow: TimeInterval? = -modDate.timeIntervalSinceNow
if modificationTimeSinceNow > seconds {
// remove file
}
}
} catch {}
}
Thanks. I'll modify this code and after testing on my app I'll create pull request.
My cleaner is ready, can you give me access to make commit and pull request?
Everybody can do a pull request. If you did a fork, then you can just do a pull request for that.
When my cached data expires it is not cleaned. Is this is correct behaviour.