Working with cache data
Applies to: Web Vuser protocols. For a list of web Vuser protocols, see Web Vuser types.
Web browsers maintain a cache of objects that are downloaded by the browser. This lets the browser load objects faster when accessing a website because it uses objects from the cache instead of downloading the objects again.
When you run a Vuser script, by default, the Vuser starts with an empty cache. This implies that the Vuser must download each object the first time that the object is required. To better emulate a real-world situation, you can provide the Vuser with a pre-defined cache at any stage while the Vuser is running. The Vuser can then access required objects directly from the cache, without having to download them.
To provide a Vuser with a pre-defined cache, first you create a file that contains the cache, and then you load the cache into the Vuser. You use the web_dump_cache function to create the cache file, and the web_load_cache function to load the cache file into the Vuser.
Create the cache file
You use the web_dump_cache function to create a cache file. The web_dump_cache function creates a file that contains all the objects that exist in the Vuser cache when the web_dump_cache function is executed. Insert the web_dump_cache function into a Vuser script, typically towards the end of the Action section of the script. This ensures that the Vuser cache contains the required objects when the web_dump_cache function is run to create the cache file. After inserting the web_dump_cache function, run the script to build the Vuser cache and create the cache file.
Note: You need to run the web_dump_cache function only once to generate the required cache file. Typically, this run is not part of a scenario. After the cache file has been created, when you run the Vuser script as part of a scenario, there is no need to execute the web_dump_cache function. Therefore you should comment-out the web_dump_cache function in the Vuser script.
You use the FileName argument in the web_dump_cache function to specify the name and location of the file to create. The FileName path can be either absolute (e.g. "FileName=c:\\MyDir\\User1.cache") or relative to the current Vuser directory (e.g. "FileName=Iteration1.cache").
- Absolute path names: Use absolute path names if you do not want the cache file to be linked to the script. For example, if you want to use a different cache on each host, use an absolute path.
- Relative path names: If you use a relative path name, the cache file is created inside the Vuser directory. When you copy the Vuser script, save it to a new location, or copy it to a load generator host, the cache file is also copied. Relative paths are independent of drive mappings and network locations.
The file extension of the cache file is always ".cache". The ".cache" extension is added if it is not specified in the FileName argument. For example, if you specify "FileName=Iteration2.txt", the cache file is called "FileName=Iteration2.txt.cache".
File names in the FileName argument can be parameterized so that different Vusers or different iterations can use different cache files. For example, "FileName=Iteration{param}.cache"
In the following example, the web_dump_cache function creates a cache file for each VuserName parameter running the script. The cache files are located in c:\temp.
Example: web_dump_cache("paycheckcache","FileName=c:\\temp\\{Vuser
Name}paycheck", "Replace=yes", LAST)
If you run a single Vuser user ten times, VuGen creates ten cache files in the following format, where the "Kunnn" prefix is the VuserName value:
Ku001paycheck.cache Ku002paycheck.cache Ku003paycheck.cache ...
Load the cache file into a Vuser
The web_load_cache function loads a cache file into a Vuser. The FileName argument in the web_load_cache function specifies the name and location of the cache file to load. The specified cache file must exist before the web_load_cache function is executed. Therefore, you can run the web_load_cache function only after running the web_dump_cache function to create the cache file.
In the following example, the web_load_cache function loads the {VuserName}paycheck cache files from c:\temp.
Example:
web_load_cache("ActionLoad","FileName=c:\\temp\\{VuserName}paycheck",LAST)
See also:
- Insert caching functions
- For details on cache functions: Function Reference (select the relevant version).