WebSetDocumentCache Function

Action

Specifies whether Silk Performer emulates a document cache. A document cache is used to keep local copies of frequently accessed documents and thus reduce the hits at the server. You can specify to always, once per session, or never check whether a page has changed on the Web server since the virtual user last viewed it.

Note: This function overrides the corresponding setting in the Simulation tab of the Profile Settings - Web dialog.

Include file

WebAPI.bdh

Syntax

WebSetDocumentCache( in bEnable : boolean,
                     in nMode   : number optional ) : boolean;

Return value

  • true if successful

  • false otherwise

Parameter Description
bEnable Specifies whether to emulate a document cache.
nMode

Specifies when to check whether a page has changed on the Web server since the virtual user last viewed it (optional). This parameter must be one of the following values:

WEB_CACHE_CHECK_SESSION
Checks once per session whether a page has changed since the virtual user last viewed it. The term of a session is the sequence of starting a Web browser, surfing the Web, and closing the Web browser. The correlation of a session to Silk Performer transactions can be adjusted with the WebSetUserBehavior function.
WEB_CACHE_CHECK_ALWAYS
Always checks whether a page has changed since the virtual user last viewed it.
WEB_CACHE_CHECK_NEVER
Never checks whether a page has changed since the virtual user last viewed it.

If this parameter is omitted, Silk Performer simulation the behavior specified in the Browser tab of the Internet Settings dialog.

Example 1 (WEB_CACHE_CHECK_SESSION)

transaction TInit
begin
  WebSetUserBehavior(WEB_USERBEHAVIOR_REVISITING);
  WebSetDocumentCache(true, WEB_CACHE_CHECK_SESSION);
  WebCookieSet("Coffee=Bean; expires=Mon, 01-Jan-2001 05:00:00 GMT; path=/",
  "http://localhost"); // The cookie's scope is TInit!!!
end TInit;
transaction TWeb
begin
  WebPageUrl("http://localhost/ResponseCookie/Cookie.asp");
  WebPageLink("Corporate", "Corporate Link");
  WebPageUrl("http://localhost/ResponseCookie/Cookie.asp");
end TWeb;
transaction TMain
begin
  WebPageUrl("http://localhost/cache/cache_form.html", "Cache Test");
  WebPageSubmit("Submit with GET", SUBMIT_WITH_GET001, "Cache Handler");
  WebPageUrl("http://localhost/cache/cache_form.html", "Cache Test");
end TMain;
dclform
  SUBMIT_WITH_GET001:
    "Get-Button" := "Submit with GET";

We will have to execute each transaction at least twice to see how caching works. We used an additional function, WebsetUserBehavior, where we specified the script was to run a returning user (user behavior WEB_USERBEHAVIOR_REVISITING), for example, an online shopper that returns to his/her favorite shopping application.

Example 2 (WEB_CACHE_CHECK_ALWAYS)

transaction TInit
begin
  WebSetUserBehavior(WEB_USERBEHAVIOR_FIRST_TIME);
  WebSetDocumentCache(true, WEB_CACHE_CHECK_ALWAYS);
  WebCookieSet("Coffee=Bean; expires=Mon, 01-Jan-2001 05:00:00 GMT; path=/",
  "http://localhost"); // The cookie's scope is TInit!!!
end TInit;
transaction TMain
begin  WebPageUrl("http://localhost/ResponseCookie/Cookie.asp");
  WebPageLink("Corporate", "Corporate Link");
  WebPageUrl("http://localhost/ResponseCookie/Cookie.asp");
end TMain;
dclform
  SUBMIT_WITH_GET001:
    "Get-Button" := "Submit with GET";

In this example, we specify the user behavior WEB_USERBEHAVIOR_FIRST_TIME. This means that each execution cycle of a transaction will be interpreted as a new user that has never visited the Web site - which is what the document cache and cookies are checking for. To achieve this, each virtual user will reset their connections, clean up their cookie database (persistent or non-persistent) and eventually clear the document cache each time a transaction has completed. When setting first time user behavior, be sure that you do not have a persistent cookie set in the TInit transaction. This cookie will not be accessible to all other transactions. It will be invalidated as soon as the transaction is done.

Example 3 (WEB_CACHE_CHECK_NEVER)

transaction TInit
begin
  WebSetUserBehavior(WEB_USERBEHAVIOR_DISABLE);
  WebSetDocumentCache(true, WEB_CACHE_CHECK_NEVER);
  WebCookieSet("Coffee=Bean; expires=Mon, 01-Jan-2001 05:00:00 GMT; path=/",
  "http://localhost"); // The cookie's scope is TInit!!!
end TInit;

The user behavior WEB_USERBEHAVIOR_DISABLE simply means that the document cache and the cookie database will be the same throughout all cycles of a transaction. The cookie database will not be reset and the document cache will not be cleared.