When controlling the cache for your application we recommend that you use the same techniques as you would when developing a 'Standard' Web Application. Please see below a few methods on how you can control the cache:
Server Side Cache-Control
OpenFin supports standard HTTP Cache-Control methods implemented in Chromium. Therefore you could control the cache on the server side. Further information on controlling the cache via HTTP headers can be found here.
Developer Tools
Open the chrome developer tools and select disable cache under the network tab. This is useful when developing your application. (your application manifest needs to have the "contextMenu"
property set to true
to access the chrome developer tools).
OpenFin Cache Management
OpenFin includes a few API calls you could use to control the cache:
System.clearCache - This API call will clear the contents of the cache, cookies, localStorage and appcache when all are set to true. This could look something like below:
const clearCacheOptions = {
appcache: true,
cache: true,
cookies: true,
localStorage: true
};
fin.System.clearCache(clearCacheOptions).then(() => console.log('Cache cleared')).catch(err => console.log(err));
System.deleteCacheOnExit - This API call will clear all cached data when the OpenFin Runtime exits. This could look something like below:
fin.System.deleteCacheOnExit().then(() => console.log('Deleted Cache')).catch(err => console.log(err));
Manually clearing the cache
You can manually clear the cache from the following location:
C:\Users<Username>\AppData\Local\OpenFin\cache
Please be aware that deleting the cache from this location could affect other applications using the same runtime.
We recommend using security realms if there is a risk of other applications being affected by deleting the runtime cache from this location. Security realms ensure all applications, not in your security realm do no have access to your applications cache (separate cache).
Information on security realms can be found here: https://developers.openfin.co/of-docs/docs/openfin-security#security-realms
Service Workers
An efficient way to control the cache of your application is by the use of service workers. There is no difference in the implementation of a service worker, whether you are doing this on the web or via OpenFin. Service workers can offer you the flexibility to run your application offline or allow you to always download updated content from your servers and then fallback to your cache (network-first recipe) other recipes can be found here.
Further information on service workers can be found here: https://developers.google.com/web/fundamentals/primers/service-workers.
A collection of working, practical examples of using service workers can be also be found here:
https://serviceworke.rs/.
Offline Access
The offlineAccess
feature loads a cached version of the application manifest, but not the startup URL. If the startup URL is not available, your application will not launch. If an application has been launched at least once and there's no internet access, the rvm will launch a locally cached config.
Furthermore, using the offlineAccess
feature correctly, your application must support HTML5 offline access. An efficient way of having your application available offline is to cache core files with the use of service workers, information on service workers is mentioned above.
This property should be included in the application manifest (top-level), documentation can be found here: https://developers.openfin.co/of-docs/docs/application-configuration
Comments
0 comments
Please sign in to leave a comment.