I'm not that familiar with using memory mapped files, but what would happen if the cached response was modified after the NSData instance was created? Presumably, something bad. I suppose the cache could be modified to update cached data in a different way to avoid this problem - preserving the old file, and creating a new one. I guess I'll have to think about this.
This may not be an issue in your apps anyway, and if not, your approach sounds ok - I don't imagine casting the data to mutable to avoid any warnings would cause problems.
If I'm understanding correctly, a side benefit to using a mapped file would be a reduction in memory use in cases where the same response is pulled from the cache multiple times. Currently, this would mean a new NSData instance with the whole response in memory for each request. I guess things could be changed so that an existing NSData instance could be returned if one already exists. Maybe this is a good idea anyway, but my reading is that 10 mapped file NSData instances would be a big improvement on 10 regular ones.
The simplest approach as the code stands would be to set a downloadDestinationPath on your requests. When a cached response is used, the request will modify the downloadDestinationPath to point at the cached response. Obviously, this means you'll have slightly more work to do in your delegate, but won't have to make any changes to ASIHTTPRequest or the cache.
Since we're talking about the cache, I have been wondering if if would make sense to move the code in useDataFromCache into ASIDownloadCache. I think the benefits of this would be a) keeping as much of the cache-related code together as possible, and b) ASIDownloadCache is a much simpler class to modify/subclass than ASIHTTPRequest (and you can replace it entirely by implementing ASICacheDelegate). I'd appreciate any thoughts on this. :)
Best
Ben
I'm not that familiar with using memory mapped files, but what would happen if the cached response was modified after the NSData instance was created? Presumably, something bad. I suppose the cache could be modified to update cached data in a different way to avoid this problem - preserving the old file, and creating a new one. I guess I'll have to think about this.
Since we're talking about the cache, I have been wondering if if would make sense to move the code in useDataFromCache into ASIDownloadCache. I think the benefits of this would be a) keeping as much of the cache-related code together as possible, and b) ASIDownloadCache is a much simpler class to modify/subclass than ASIHTTPRequest (and you can replace it entirely by implementing ASICacheDelegate). I'd appreciate any thoughts on this. :)