Search code examples
iphoneiosuitableviewcachingasihttprequest

how to access cache from other views


I have set up a sharedCache using ASIHttprequest and it is created from the xml I parse in my subview. I was woundering if I can then access that sharedCache from my mainview to do a few things things that will speed my tables up?

any idea, suggestions, thoughts of examples would be greatly appreciated.


Solution

  • There's already a sharedCache provided by ASIDownloadCache. It's visible anywhere in your application (assuming you #import "ASIDownloadCache.h"), so you should be able to call [ASIDownloadCache sharedCache] and use it.

    EDIT: To use several caches is not too tricky. Create a separate class which is included by both your main view and your subview. In there, define a method to return one or more ASIDownloadCache objects, and provide an implementation, similar to this:


    DownloadCaches.h

    #import "ASIDownloadCache.h"
    
    @interface DownloadCaches : NSObject
    
        + (ASIDownloadCache *)imageCache;
    
    @end
    

    DownloadCaches.m

    #import "DownloadCaches.h"
    
    @implementation DownloadCaches
        static ASIDownloadCache *imageCache = nil;
    
        + (ASIDownloadCache *)imageCache
        {
            if(imageCache == nil)
            {
                imageCache = [[ASIDownloadCache alloc] init];
                // set imageCache-specific options here
            }
    
            return imageCache;
        }
    
    @end
    

    You only ever need to call [DownloadCaches imageCache] and it will be initialised if not already, and then returned to you.