Exercise 1: Use a caching Application block to improve performance
This exercise will demonstrate how to use the cached application block in the Enterprise Library and increase the speed at which data is displayed.
First step
Open the EmployeeBrowser.sln project, the default installation path should be C:\Program Files\Microsoft Enterprise Library January Exercises\ex01\begin, and compiled.
The second step is to populate the QuickStarts database with data
Run batch file Setcachinghol.bat, the default installation location is C:\Program Files\Microsoft Enterprise Library January 2006\labs\cs\caching\setup. This creates a employees datasheet in the QuickStarts database, inserts some test data, and creates the appropriate stored procedure. The default database server is (local) \SQLExpress, if you need to change, please open setcachinghol.bat with Notepad, modify it yourself.
Third Step Review Application
1. This application is used primarily to read and view employee details from the database, as part of the application, and to browse the employee's photo information.
2. Select the MainForm.cs file in the project Employeebrowser, select View | The Code menu command and navigates to method Mainform_load, the form class is displayed by EmployeeService fetch data, and it uses Employeedataprovider to return the data, as shown in the following illustration:
Note Now that EmployeeService is only a delegate to Employeedataprovider, we will use the cache application block here.
3. Select the EmployeeDataProvider.cs file in Solution Manager, select View | The Code menu command and navigates to the Getemployeephotodata method. Note that the access to the database has been delayed for a second.
4. Select Debug | The Start without Debugging menu command runs the application. Notice that there is a certain delay in browsing the employee's photos.
Step fourth implement caching in the EmployeeService class
1. Select Project Employeebrowser, and select Projects | Add Reference ... menu command, select the browse item in the pop-up dialog box and add the following assembly.
Microsoft.Practices.EnterpriseLibrary.Caching.dll