Caché Server Pages (CSP) technology allows you to build and deploy high-performance, highly-scalable Web applications. CSP lets you dynamically generate Web pages, typically using data from a Caché database. These pages are dynamic; that is, the same page may deliver different content each time it is requested.
CSP is versatile. It can
CSP is well-suited for database applications. In addition to providing rapid access to the built-in Caché database, it provides a number of features essential for Web-based database applications including
CSP supports two styles of Web development.
Caché Server Page requests are processed using a standard Web server (all the leading servers are supported) and the standard HTTP protocol. CSP manages communications between the Web server and Caché and invokes application code to generate the page. The request and return process is as follows:
  1. An HTTP client, typically a Web browser, requests a page from a Web server using HTTP.
  2. The Web server recognizes this as a CSP request and forwards it to Caché using a fast server API.
  3. The CSP Server running in Caché processes the request and returns a page to the Web server.
  4. The Web server sends it to the browser for display.
The Web Server and the Caché server are abstract components, which may be implemented by one or many computers. During development, all three components may be on a single PC. In a large scale deployment, there may be multiple Web and Caché servers in two- or three-tier configurations.
To keep this guide simple, it treats these components as though there were one of each. It also describes CSP as though it was only serving HTML pages, although almost everything applies directly to XML and other text formats and most things apply to binary formats such as images.
Before You Start
To be productive with CSP you should have some familiarity with the following:
Some useful resources for learning HTML and JavaScript include:
CSP Samples
Caché comes with a set of sample CSP pages. To view these:
  1. Start Caché.
  2. Make sure that the local Web server on your machine (such as IIS or Apache) is running.
  3. Start your browser and go to this page:
    Where 8972 is your Caché server port number.
  4. If you have activated any of the advanced security features in Caché, a login page might display. Log in.
  5. Caché displays a list of sample CSP pages along with a short description of each. Click on any that interest you.
CSP Tutorials and Online Documentation
To set up the CSP Gateway, see
There are three online tutorials to help you learn to create CSP pages:
The following online documentation is also available, including this book:
Class reference information for these classes:
Creating Your First CSP Application
No introduction to a development technology is complete without the ubiquitous Hello, World example. This section includes a demonstration of how to create a Hello, World CSP page in two different ways.
Creating a Class-based CSP Page
Create a CSP page by creating a subclass of %CSP.Page and overriding its OnPage method. Any output written to the principal device by this method is automatically sent to a Web browser and displayed as a Web page.
To create a Hello, World page programmatically, do the following:
  1. Start Caché Studio.
  2. Create a new project in the local database USER namespace by selecting File > New Project.
  3. Create a new class definition by selecting File > New > New Class Definition.
  4. On the first page of the Wizard, specify Test for the package name and Hello for a class name
  5. On the second page, select CSP as the class type.
  6. Click Finish. You see the new CSP class definition in the Studio Class Editor:
    Class Test.Hello Extends %CSP.Page [ ProcedureBlock ]
    {
        ClassMethod OnPage() As %Status
        {
            &html<<html>
            <head>
            </head>
            <body>>
            ;To do...
            &html<</body>
            </html>>
            Quit $$$OK
        }
    }
  7. In the OnPage method, replace the comment:
     ; To do...
    With a Write statement:
     Write "<b>Hello, World</b>",!
     
  8. Save and compile the new class using Build > Compile.
  9. Start a browser and enter the following URL: http://localhost/csp/user/Test.Hello.cls
You see Hello, World displayed in the browser.
This application works as follows:
  1. The browser sends a request for Test.Hello.cls to the local Web Server
  2. The Web Server passes this request to the CSP Gateway (connected to the Web Server) which, in turn, passes the request to a Caché CSP Server. In our case the browser, the Web server, and the Caché Application server are all running on the same machine. In a real deployment, these would probably be on separate machines.
  3. The Caché CSP Server looks for a class called Test.Hello and invokes its OnPage method (which we edited in Caché Studio).
  4. Any output that the OnPage method writes to the principal device (using the Write command) is sent back to the browser (via the CSP Gateway and the Web Server).
These steps are at the heart of CSP: The rest of CSP's functionality is built on top of this behavior.
If you like, you can make your example application more interesting by adding more code. For example, insert the following lines after the line containing Hello, World:
 Write "<ul>",!
 For i = 1:1:10 {
    Write "<LI> This is item ", i,!
 }
 Write "</ul>",!
 
Now your page contains an unordered (bulleted) list of 10 items. Note that, in this context, Caché uses the exclamation point (!) character to write a carriage return to the principal device.
Creating an HTML Tag-Based CSP Page
Another way to create a CSP page is to create an HTML file and let the CSP compiler transform it into a CSP class.
To create a Hello,World page using an HTML file, do the following:
  1. Start Caché Studio and select File > New > CSP File > Caché Server Page.
  2. Edit the new CSP file in the Studio CSP Editor (which offers CSP and HTML syntax coloring) and add the following:
    <html>
    <body>
    <b>Hello, World!</b>
    </body>
    </html>
  3. Save the page as Hello.csp.
  4. Start your browser and type in the following URL: http://localhost/csp/user/Hello.csp
As with the previous example, you see Hello, World displayed in the browser.
Note:
You can also create an HTML file using a text editor or HTML editor. Save this file as Hello.csp in the local directory /cachesys/csp/user (where cachesys is where you have installed Caché).
This application works as follows:
  1. The browser sends a request for Hello.csp to the local Web Server
  2. The Web Server passes this request to the CSP Gateway (connected to the Web Server) which, in turn, passes the request to a Caché CSP Server.
  3. The Caché CSP Server looks for the file Hello.csp, and hands it to the CSP compiler.
  4. The CSP compiler creates a new class called csp.Hello with an OnPage method that writes out the contents of the Hello.csp file. (It actually generates a set of methods each of which are, in turn, called from the OnPage method). This compilation step only occurs when the .csp file is newer than the generated class; subsequent requests are sent directly to the generated class.
  5. The CSP Server now invokes the newly generated OnPage method and its output is sent to the browser as in the previous example.
As with the case of programmatic development, this is a purposefully oversimplified example included for pedagogical reasons. The CSP compiler is actually a specialized XML/HTML processing engine that can:
As with the programmatic example, you can make this page more interesting by adding programming logic. For example:
<html>
<body>
<b>Hello, World!</b>
<script language="CACHE" runat="server">
 // this code is executed on the server
 Write "<ul>",!
 For i = 1:1:10 {
    Write "<li> This is item ", i,!
 }
 Write "</ul>",!
</script>
</body>
</html>
As with the programmatic example, the resulting page displays an unordered (bulleted) list of 10 items.