Caching is an important aspect of web scripts and is often required to support
high-load applications such as Internet websites backed by the SkyVault content application
server. You should consider caching when developing web scripts.
This task demonstrates cache controls by creating a sample web script that sets the
last modified date.
-
Log in to SkyVault Explorer:
- Open a web browser and enter the URL: http://localhost:8080/SkyVault
- If prompted, log in with the user name admin and password admin.
- Navigate to Company Home > Data Dictionary > Web Scripts Extensions.
-
Create a folder to represent the top-level package structure (skip this step if the
org space already exists):
- In the Create menu, click Create Space.
- Enter the name for the folder in the Name field, such as: org
- Click Create Space.
-
Create a sub-package (skip this step if the example space already
exists):
- Navigate to Company Home > Data Dictionary > Web Scripts Extensions > org.
- In the Create menu, click Create Space.
- Enter the name for the folder in the Name field, such as: example
- Navigate to Company Home > Data Dictionary > Web Scripts Extensions > org > example.
-
Create a web script description document for your cache sample:
- In the Create menu, click Create Content.
-
Enter the name for the web script in the Name field as:
cache.get.desc.xml
- In the Content Type list, select XML.
- Click Next.
-
Type the following in the Enter Content box:
<webscript> <shortname>Cache example</shortname> <description>Demonstrate cache controls</description> <url>/cache</url> <authentication>user</authentication> <cache> <never>false</never> <mustrevalidate/> </cache> </webscript>
- Click Next, click Finish, and then click OK.
-
Create a controller script for your cache sample:
- In the Create menu, click Create Content.
-
Enter the name in the Name field, such as:
cache.get.html.ftl
- In the Content Type list, select Plain Text.
- Click Next.
-
Type the following in the Enter Content box:
Cached response
- Click Next, click Finish, and then click OK.
-
Register the web script with SkyVault.
- In a web browser, enter the URL: http://localhost:8080/alfresco/service/index
- If prompted, log in with the user name admin and password admin.
- Click Refresh Web Scripts.
A message indicates there is an additional web script.
Remember: The Web Script Framework does not perform any caching of its own. It ensures correct HTTP headers are transmitted based on the web script cache controls for an external cache to interpret. -
Test your cache sample with cURL by typing the following in your command line:
curl -uadmin:admin -v "http://localhost:8080/alfresco/service/cache"
The returned response is similar to the following, where the Cache-Control and Last-Modified headers are present:
* About to connect() to localhost port 8080 (#0) * Trying ::1... connected * Connected to localhost (::1) port 8080 (#0) * Server auth using Basic with user ‘admin’ > GET /alfresco/service/cache HTTP/1.1 > Authorization: Basic YWRtaW46YWRtaW4= > Host: localhost:8080 > Accept: */* > < HTTP/1.1 200 OK < Server: Apache-Coyote/1.1 < Cache-Control: must-revalidate < Last-Modified: Tue, 02 Feb 2010 09:07:05 GMT < Content-Type: text/html;charset=UTF-8 < Content-Length: 16 < Date: Tue, 02 Feb 2010 09:07:05 GMT