This Question is Assumed Answered

1 "correct" answer available (8 pts) 12 "helpful" answers available (5 pts)
7 Replies Last post: Nov 20, 2008 11:17 PM by ABC XYZ  
ABC XYZ BlackBelt 285 posts since
Mar 6, 2008
Currently Being Moderated

Nov 12, 2008 6:47 AM

Embedding/ Caching Binary Resources

Hi

 

Suppose a Curl applet is using certain images/sound files and we do not want to rely on browser caching and wants to avoid repeat download of such heavy files again-n-again.

Rather we'll cache the files into a folder locally on their first use and further I'll directly use those images/sound in my curl applet from the local store.

 

How to implement such things in curl ?

 

Thank you.

Duke BlackBelt 294 posts since
Oct 17, 2007
Currently Being Moderated
1. Nov 12, 2008 1:52 PM in response to: ABC XYZ
Re: Embedding/ Caching Binary Resources

If the applet is privileged (perhaps through using code signing), then you can store the files wherever you want.

 

Another alternative for all applets would be to use request-local-data-permission to get a local file storage directory that you can refer to using the url curl://local-data/.  This will present a security approval dialog to the user of an unprivileged applet the first time it is called (and not later if the directory already exists).

 

If you make your applet an OCC (occasionally connected computing) applet, then all your resource files can be copied and installed locally for you.  OCC applets take care of the details of storing code and data in local storage that is not the browser cache.  See the documentation on OCC applets for more about them.  OCC applets can be used for applications that can run even when disconnected from the network.

Duke BlackBelt 294 posts since
Oct 17, 2007
Currently Being Moderated
3. Nov 19, 2008 3:28 PM in response to: ABC XYZ
Re: Embedding/ Caching Binary Resources

If you could avoid actually checking the file system repeatedly by keeping a hash table of known results, that should help the performance.

 

Or, maybe you could rewrite your code to use try / catch to retry an operation if the resource is not already available locally (after getting it in the local storage using the catch clause).

Christopher Barber BlackBelt 137 posts since
Sep 27, 2007
Currently Being Moderated
5. Nov 20, 2008 10:57 AM in response to: ABC XYZ
Re: Embedding/ Caching Binary Resources

You could embed resources in global variables in your package, but it is up to you to figure out how to encode the resource data in code. I would only consider doing this for very small and frequently used resources, since otherwise you could considerably bloat the size of the package, which could cause it to take longer to load and take up more process memory.

Duke BlackBelt 294 posts since
Oct 17, 2007
Currently Being Moderated
6. Nov 20, 2008 7:25 PM in response to: ABC XYZ
Re: Embedding/ Caching Binary Resources

Your resource files would not be kept in the Curl compiled package cache, unless you somehow encode the data in your Curl source code, as cbarber is talking about.  That does not sound like a convenient or efficient idea.

 

If you know the resource files (*.jpg, *.mp3) ahead of time, and they are in the project directory, then if you add them as resources to your project with a deploy setting of "copy", then you can have them deployed for OCC.  Using the IDE to deploy the project for OCC will put all the files together into a compressed archive file, curl-archive.car .  Then users install the OCC applet from your website, which will download the compressed archive and expand the archive into the local directory created for use by OCC applets (on Windows, typically a location like file:///c:/Documents and Settings/duke/Local Settings/Application Data/Curl Corporation/Surge/local-root-for/ ).

 

The use of InflateByteInputStream is a good idea if you don't know the files ahead of time or cannot put them in the project directory.  However, since jpeg and mp3 are already compressed, it would not be that beneficial to be compressing them again.  Other types of files could see a lot of benefit from a compression step though.

 

In the version 7.0 of Curl OCC, I think there will be a preference for running OCC applets from the local disk copy, while in Curl 6.0 you would run from the network (using your browser cache) if your computer was connected to the network at the time you started your applet using the special URL like curl://occ/http://www.curl.com/developers/occ2/app1.curl

More Like This

  • Retrieving data ...