The cache of the Flex or flash client is not the browser cache. the browser cache will expire after a certain period of time.
The biggest problem for websites developed using Flex or flash is that the SWF file is too large and the domestic network speed is limited, resulting in a long loading time, which will lead to the loss of many potential customers.
Flex uses RSL technology to solve the cache and sharing of the Framework, and largely solves the loading problem. However, if the project is too large, the loading time may be too long. I used mongodobject to cache SWF and module on the client, and to perform version control. Create a configuration file on the server. If the client has cached data, perform version control to keep the client data the same as that on the server.
Example:
Assume that there is an applicationproject. The generated application.swf file is 2028 kb, And the download speed of the client is 100 K/s. It takes about 20 seconds. Now, the app source code is extracted and changed to application.swf 428k, module1.swf 1000k, and module2.swf 600 K by using the lelemechanism. 428 K of the shard, about 4 seconds. In addition, the moduel read time is 2 seconds, and the maximum time is 6 to 7 seconds. The efficiency is obvious. The ingress is also cached.
Problem:
If the client does not allow caching, the cache will be skipped. Program .
If a user opens this website multiple times, the user is interested in this website. After being asked multiple times whether the cache is allowed, the possibility of clicking yes is also increased.
When users have a clear understanding of the benefits of the cache, the cache is allowed. 1. It can accelerate user experience, 2. It can reduce server pressure, and 3. It can reduce server bandwidth usage.
Article Finally, there is a demo for download and testing, Source code Temporarily packaged into SWC, not open.
The following explains how to use warmc. SWC:
Configuration File 'cache _ config. xml'
<Data id ="Moduleone"Version ="Beta01"/><Data id ="Moduletwo"Version ="Beta01"/><Data id ="Myswf"Version ="Beta01"/>
* Of course, you can choose the path and name of the configuration file, but you need to specify the path during version control. The following describes how to start version control.
* ID attribute. The cached name will be used globally, including the cached mongodobject name and version control. This ID will be used to read the cache below
* Version control, with your name. However, to ensure that it is not confused with previous versions, we recommend that you use an incremental version name.
You must first start version control before using the cache. You need to import the following packages:
Import warmc. cache. locationdataproxy;
Then start version control:
Locationdataproxy. getinstance (). cacherebuild (0.5 );
Cacherebuild (size: int, configurl: string) method instructions:
* Size parameter, which specifies the total cache size. The unit is mb. If this parameter is left blank, the default value is 1 MB. When running to this location, the client's mongodobject allows the cache size, then, the user is prompted to modify the maximum value of the cache. If the data to be cached is large, the value corresponding to the value below can be modified.
Size <= 0 is not displayed, or the Default Client size is kb.
0 1 <= size <10 data cached within 10 MB
10 <= size: cache infinite data
For example, if the total size of the file to be cached is 700 KB, you can set size to 0.7. In this way, you will ask the user about the version control, and ensure that the user agrees not to ask again after caching
* Configurl refers to the XML address of the configuration file, which is in the root directory 'cache _ config. xml' by default. It must be specified and the configuration file format must be consistent with the demo format.
* If the configuration file is correct, version control starts successfully and reads the server configuration and compares it with the Client Cache version. If the version is different, delete the client cache. If version control fails to be started, the client cache cannot be synchronized with the server cache.
Set the user-friendly cache Function
Locationdataproxy. getinstance (). warm_human (true );
Warm_human (bool: Boolean) Description:
* When flashplayer's sharedobject is used beyond the size set by the client, the user will be prompted, asking for comments, whether to agree to the website Cache
* If the system needs to cache multiple data records and the user rejects the cache, the system will ask whether to allow the cache every time it needs to write mongodobject, the user experience is terrible.
* When the value of warm_huma is set to true, after the first prompt is sent to the user whether to allow the program cache to change the size, if the user rejects the request, the future cache will not be prompted or cached on the client, until the user runs the program again (although it is a little annoying, it is too troublesome, most people do not care about the M space, but click to allow)
* False. no matter whether the user rejects the request, the user will be prompted every time the cache area needs to be increased by an hour.
* If this method is not used, the default value is true. Therefore, this method is rarely used.
After the version control is successfully started, you can load the module and import the following package first:
Import warmc. cache. modulecacheproxy;
Load Module
Modulecacheproxy. getinstance (). load ("moduleone", "moduleone.swf", onprogress, onready); function onprogress (bytesloaded: uint, bytestotal: uint): void {trace ("> load moduleone: "+ bytesloaded +"/"+ bytestotal);} function onready (data: Object): void {trace ("> moduleone loaded! "); Application. application. addchild (data as uicomponent );}
* Load (Name: String, URL: String, onprogress: function, onready: function) Description:
* Name indicates the ID of the module in the configuration file cache_config, which must be consistent with the configuration file. Used for version control and
Client Cache file name, get mongodobject through name
* URL refers to the SWF file path of the module. The module file of the demo is in the root directory, so you can directly specify the name.
* Onprogress refers to the progress callback method when the module is loaded. Two parameters, bytesloaded and bytestotal, are returned. If you need to display the progress bar, this method is required. If the cache does not exist, bytesloaded and bytestotal will load data from the server;
If the cache already exists, this method is called only once, and both return parameters are 100
* Onready refers to the callback method after loading. It returns a parameter data of the uicomponent type.
* The agent uses the hunger Singleton mode to check whether the module has been cached on the client.
* If it is already cached on the client, it is directly read
* Otherwise, load the file from the server, display the file, cache the file to the client, and enter the version.
To load SWF (non-module), you need to import the following package:
Import warmc. cache. swfcacheproxy;
Load SWF:
Swfcacheproxy. getinstance (). load ("myswf", "test.swf", onprogress, onready); function onprogress (bytesloaded: uint, bytestotal: uint): void {trace ("> load SWF: "+ bytesloaded +"/"+ bytestotal);} function onready (data: Object): void {trace ("> SWF loaded! "); Var load: loader = new loader () load. loadbytes (data as bytearray); var UIC: uicomponent = new uicomponent (); UIC. addchild (load); application. application. addchild (UIC );}
* Load (Name: String, URL: String, onprogress: function, onready: function) Description:
* Attributes serve the same purpose as modulecacheproxy.
* The only difference is that the onready method's return parameter is a bytearray, which needs to be packaged and used by itself. You can use swfcacheproxyto save skin style.swf, game plug-ins, image resources, and other SWF data.
In this example, there is a "load module 2 ":
Private function loadmodule2 (): void {modulecacheproxy. getinstance (). load ("moduletwo", "moduletwo.swf", onprogress, onready); modulecacheproxy. getinstance (). load ("moduletwo", "moduletwo.swf", onprogress, onready); function onprogress (bytesloaded: uint, bytestotal: uint): void {trace ("> load moduletwo: "+ bytesloaded +"/"+ bytestotal);} function onready (data: Object): void {trace ("> moduletwo loaded! "); Application. application. addchild (data as uicomponent );}}
Specifically, you will find that moduletwo.swf is loaded twice using modulecacheproxy. Well, this is to demonstrate that if a SwF has not been loaded, it will be rejected if it is loaded again. If you want to load one SWF multiple times at a time (or copy multiple SWF files), it will be rejected. you can load it one by one in the onready method. Or you can simply use replication instead of loading, copy it, and Google it yourself.
In this way, the cache loading is quite slow.
In addition, be honest. Don't put anything on the drive C.
Let's take a look at the demo. If any bug is found in the flex Client Cache module SWF, leave a message...
Reprinted Please note: From flexhome
Link: http://flex.desizen.com/flex-client-cache/