Enterprise Library
Quick Start is a simple and easy-to-understand applicationProgramAn example of the key features of a block is used to describe these features using a roaming set that implements common scenarios.
If you want to understand an Application Block, the Quick Start is the ideal starting point, and you can use the testSource codeIt is also very comfortable to learn new technologies. If
The framework is familiar, and it helps you understand how to solve specific problems if you want to view the simpleCodeFor example, they are very good resources.
To use all the advantages of Quick Start, you need to be familiar with the concepts and technologies related to object-oriented programming.
Cache Quick Start
The Quick Start application demonstrates some key features of the cache application block. It uses a roaming set to demonstrate these features. Roaming is the implementation of the situation discussed in "key scenarios", as follows:
Roaming: Add entries to the cache
Roaming: Remove entries from the cache
Roaming: Get entries from the cache
Roaming: Clear Cache
Roaming: loading Cache
Quick Start uses a top-level handler to capture any exceptions in any scenario. The handler displays a dialog box with exception information.
System Requirements
To build and run Quick Start, you will need the following software:
Microsoft Windows 2000, Windows XP Professional, or Windows
Server 2003 Operating System
Microsoft. NET Framework 2.0
Microsoft Visual Studio 2005 Development System
Quick Start does not need to perform any installation steps before building and running applications.
Note:
The default Quick Start configuration does not use persistent backend storage.
Build and run Quick Start
Quick Start is released in the form of source code, which means you must compile it before running. You can use Visual Studio to build quick start.
Quick start to build Cache
Check that the Enterprise Library source code is installed.
Open Enterprise Library from Windows Resource Manager
Source code folder, or use the Start Menu shortcut to open it: In the taskbar, clickStart, Pointing
Program, PointingMicrosoft patterns
And practices, PointingEnterprise Library 3.1
-May 2007:And then selectEnterprise Library 3.1
Source folder.
OpenQuickstarts
Folder, and then
Cache
And thenCS
(For C #) or
VB
(For Visual Basic. net ).
Double-clickCachingquickstart. sln
Icon.
Open and display the solution file in Visual Studio. In the menu, click
Generate.
ClickRegenerate Solution. By default, this is a debug
Build.
Press F5 To Run quick start.
Quick Start Configuration
The Quick Start configuration information is stored in the Quick Start project folder, which has the following attributes:
The cache manager for the cache operation section is named "Default cache ".
Manager ". The cache manager is named "loading scenario Cache
Manager ".
Data is only written in memory (rather than back-end storage ).
An expiration cycle occurs every 60 seconds.
Cleaning occurs when there are 1000 entries in the cache.
Removes 10 entries from the cache.
In the Quick Start, roaming has a defined configuration, which is included inApp. config
File. This file is placed in the folder of the Quick Start project file.
To modify or view these settings, use the Enterprise Library configuration console to open the app. config in the directory containing the Quick Start project file.
File. App. config contains configuration data.
Each time you build code, Visual Studio copies app. config
File to the project output directory (the directory of the created Quick Start Executable File) and renamed it cachingquickstart.exe. config.
This means that if you want to use the configuration console to modify any configuration settings, such as the expiration period and plan to recreate the solution, you must open the app. config in the Quick Start source directory.
File to modify the configuration. You can use the configuration console to open cachingquickstart.exe. config
File. However, these changes will be overwritten in the next successful build.
This means that when you use the configuration console to open app. config
File and modify the configuration settings, you must copy the file to the output directory. You can manually copy or recreate a project to achieve this goal. Remember, there is no need to recreate the code to simply modify the configuration settings. The command running on the successful build is to facilitate the build.
Roaming: Add entries to the cache
This roaming shows how to add entries to the cache.
Reconstruction example
-
Configure cache. For required steps, see enter configuration information.
-
InQuickstartform
Class is
Cachemanager
Object declares a member variable.
Example 7.21. C #
Private cachemanager primitivescache;
Example 7.22. Visual Basic. net
Private primitivescache as cachemanager
-
In the quickstart_load
method, add the following code to create
cachemanager
. The call to
getcachemanager
does not contain the name of cachemanager
, therefore, the factory created the default
cachemanager
Object declared in the configuration file.
example 7.23. C #
This. primitivescache = cachefactory. getcachemanager ();
example 7.24. visual Basic. net
me. primitivescache = cachefactory. getcachemanager ()
-
Create an entry to be added to the cache. The following code creates an entry of the product
type.
example 7.25. C #
string id = "productoneid";
string name = "productonename ";
int price = 50;
product Product = new product (ID, name, price );
example 7.26. visual Basic. net
dim ID as string = "productoneid"
dim name as string = "productonename"
dim price as integer = 50
dim newproduct as product = new product (ID, name, price)
Add entries to the cache. The following code usesAdd
An overload of the method. The reload includes the cleanup priority (2 here), the instructions that are not refreshed when the entry expires, and the 5-minute expiration time starting from the last access time of the entry.
Example 7.27. C #
Primitivescache. Add (product. productid, product, cacheitempriority. Normal, null,
New slidingtime (timespan. fromminutes (5 )));
Example 7.28. Visual Basic. net
Primitivescache. Add (newproduct. productid, newproduct, cacheitempriority. Normal, nothing ,_
New slidingtime (timespan. fromminutes (5 )))
Roaming: Remove entries from the cache
This roaming shows how to remove entries from the cache.
Recreate this example
-
Configure cache. For the necessary steps, see "Quick Start configuration" in cache quick start ".
-
declare an object in the quickstartform
class as
cachemanager
A member variable.
example 7.29. C #
private cachemanager primitivescache;
example 7.30. visual Basic. net
private primitivescache as cachemanager
Add the following code in the response to the user request to remove entries from the cache.
Example 7.31. C #
// Prompt the user for the key of the item to be removed.
If (this. selectitemform. showdialog () = dialogresult. OK)
{
// Request that the item be removed from the cache.
This. primitivescache. Remove (selectitemform. itemkey );
}
Example 7.32. Visual Basic. net
'Prompt the user for the key of the item to be removed.
If (Me. selectitemform. showdialog () = dialogresult. OK) then
'Request that the item be removed from the cache.
Me. primitivescache. Remove (selectitemform. itemkey)
End if
Roaming: Get entries from the cache
This roaming shows how to obtain entries from the cache.
Reconstruction example
Configure cache. For more information, see "Quick Start configuration" in cache quick start ".
-
InQuickstartform
Class is
Cachemanager
Object declares a member variable.
Example 7.33. C #
Private cachemanager primitivescache;
Example 7.34. Visual Basic. net
Private primitivescache as cachemanager
Add the following code in the method that responds to a user request to read entries from the cache.
Example 7.35. C #
// Prompt the user for the key of the item to be read.
If (this. selectitemform. showdialog () = dialogresult. OK)
{
// Read the item from the cache. If the item is not found in the cache,
// Return value will be null.
Product = (product) This. primitivescache. getdata (selectitemform. itemkey );
}
Example 7.36. Visual Basic. net
'Prompt the user for the key of the item to be read.
If (Me. selectitemform. showdialog () = dialogresult. OK) then
'Read the item from the cache. If the item is not found in the cache,
'Return value will be null.
Dim requestedproduct as product = directcast (Me. primitivescache. getdata (selectitemform. itemkey), product)
End if
Roaming: Clear Cache
This roaming shows how to clear the cache and clear all the data in the cache.
Recreate this example
-
Configure cache. For more information, see "Quick Start configuration" in cache quick start ".
-
declare an object in the quickstartform
class as
cachemanager
A member variable.
example 7.37. C #
private cachemanager primitivescache;
example 7.38. visual Basic. net
private primitivescache as cachemanager
-
Add the following code in the response to the user request to clear the cache.
example 7.39. C #
This. primitivescache. flush ();
example 7.40. visual Basic. net
me. primitivescache. flush ()