Closed kapilgoenka closed 13 years ago
You will notice that method returns the variable diskCacheUsage which is not initialised anywhere. I was thinking of rewritting that as a property to hook the first call and search the directory adding up the sizes of the files found there.
yeah I noticed that just after posting the question. So instead of returning the variable diskCacheUsage, I am reading the value from the diskCacheInfo dictionary. Does this look good?
Should work. Maybe it would be better to hook the initialisation of diskCacheInfo (line 234) to set the class variable there so you don't have to query the dictionary in the public accessor.
thanks for pointing that out. I like your approach better.
Also, I was having the problem mentioned at http://stackoverflow.com/questions/2153268/nsurlcache-memory-size-is-zero (i.e. memory capacity zero). I adopted Doug's method from that page, which I am also printing below: -(void)setMemoryCapacity:(NSUInteger)memCap{ if (memCap == 0) return; [super setMemoryCapacity:memCap]; }
Have you also encountered this yet? Is there likely any side effect of adding this method to SDURLCache?
I haven't reached that far yet but I would first check memory warnings in the simulator. Maybe calling setMemoryCapacity:0 is the way in which Apple releases memory, in which case you would prevent the memory from being freed, thus making your application consume more than necessary, get killed if in background or worse, be unable to work properly if you have several active web views and crash to the user.
You can verify this setting a breakpoint in the setMemoryCapacity method and using the simulator's memory warning option.
Thanks for your responses. Much appreciated.
I have a method that prints the current disk usage & the current memory usage. I do some activity in my app & verify that these numbers are both non-zero. Then when I restart my app, both these numbers go back to zero. I can understand memory usage going back to zero, but can't understand why the disk usage goes back to zero too? After the restart, I can still see the files that SDURLCache created on disk which means that the caching had indeed succeeded. I am testing against iOS 4.2.1 on an iPad. I'm calling [[NSURLCache sharedURLCache] currentDiskUsage] to get the disk usage.