0 Replies Latest reply on Jun 11, 2012 2:07 AM by Samliu_tw

    Something wrong with ContentCache??

    Samliu_tw

      I use ContentCache in IconItemRenderer to load images from web, and it work perfect. No matter how I scroll List component, images can be displayed immediately. But if I load images from local storage, images always delayed a short time. Why?

       

      This is my code:

       

      public class ImageCacheFromLocalStorage extends ContentCache
      {
       override public function load(source:Object, contentLoaderGrouping:String=null):ContentRequest
       {
        var picurl:String = source is URLRequest ? (source as URLRequest).url : source as String;
        var picname:String = picurl.split("/").pop() as String;
        var picfile:File = File.applicationStorageDirectory.resolvePath("cache/" + picname);
        if (picfile.exists)
        {
         trace("Request Image From [Local Storage]:", picfile.url);
         return super.load(picfile.url, contentLoaderGrouping);
        }
        else
        {
         trace("Request Image From [Web]:", picurl);
         var request:ContentRequest = super.load(source, contentLoaderGrouping);
         (request.content as LoaderInfo).addEventListener(Event.COMPLETE, loader_completeHandler);
         return request;
        }
       }
      
       protected function loader_completeHandler(event:Event):void
       {
        // Save Images to Local Storage
       }
      
      }