7.2 [Enterprise Library] Use cache application blocks to develop applications

Source: Internet
Author: User
Tags configuration settings

This article is part of the Enterprise Library 3.1 help document for Chinese translation.

This section describes how to use a cache application.ProgramBlock to develop applications. First, it explains how to configure the Application Block, add it to the solution, and select a backend storage. Then, in key scenarios, it describes how to use application blocks in specific scenarios, such as adding entries to the cache and removing entries from the cache.

All application blocks useSource codeProvide (ship ??), Therefore, you must compile them before using the Quick Start and configuration tools. Learn how to compile enterprise
Library SourceCodeFor more information, see build an Enterprise Library.

Enter configuration information

These procedures explain how to configure cache application blocks. The node-related attributes are displayed on the right panel. If you want to use the data access application block as the backend storage, you must configure this application block before configuring the cache application block.

Add application blocks
    1. Open the configuration file. For more information, see configure application blocks.

    2. Right-clickApplication configuration, Pointing
      NewAnd then click
      Cachingapplicationblock.

    3. Configure the console to automatically addCachemanagerNode.

Configure cache manager)
    1. click the caching Application Block node.

    2. (optional) modify the defaultcachemanager
      attribute name. If the Code does not specify a specific cache manager, the default cache manager is used. Enter a new name or select one from the drop-down list. The default name is
      cachemanager .

    3. click cachemanager
      node (if the cache manager has been renamed, the node will have the assigned name ).

    4. (optional) set the expirationpollfrequencyinseconds
      attribute. This is the frequency at which the timer controls how often the background scheduler checks for expired entries. The Unit is seconds. The minimum time is 1 second. The default value is 60 seconds.

    5. set the maximumelementsincachebeforescavenging
      attribute. This is the maximum number of elements that can be cached before being cleared. The default value is 1000.

    6. (optional) Rename the cachemanager node. The default name is
      cachemanager .

    7. set the numbertoremovewhenscavenging
      attribute. This is the number of elements removed after the removal starts. The default value is 10.

By default, cache storage entries are only in the memory, and the value assigned to the backend storage isNullbackingstore
. You can configure cache application blocks to use database cache storage, independent storage, or custom storage. Database cache storage uses data to access application blocks.

Configure cache application blocks for database cache storage
    1. Right-clickCachemanager(Or the renamed cache manager name), pointing
      NewAnd then click
      Databasecachestorage.

    2. Configure the console to automatically add data access application blocks. For information on configuring Data Access application blocks, see the Data Access Application Block documentation.

    3. ClickDatacachestorageNode.

    4. SetDatabaseinstance
      Attribute. This is the name of the database connection string, which must correspond to the name of a connection string in the data access application block configuration. You can enter a name or select it from the drop-down list.

    5. (Optional) RenameDatacachestorageNodes to set
      NameAttribute.

    6. SetPartitionname
      Attribute. This identifies the database part that the cache manager will use.

Configure cache application blocks for independent storage
    1. Right-clickCachemanager(Or the renamed cache manager name), pointing
      NewAnd then clickIsolated
      Storage.

    2. If you want to encrypt the information stored in the independent storage, right clickIsolated Storage, Pointing
      NewAnd clickSymmetric Storage
      Encryption
      . Configure the console to automatically add encryption application blocks. For more information about how to configure the encrypted application block, see the document for encrypting the Application Block.

    3. (Optional) RenameIsolatedstorage
      Nodes to setNameAttribute.

    4. SetPartitionname
      Attribute. This identifies the region of the independent storage that the cache manager will use.

Configure cache application blocks for custom cache storage
    1. right-click cachemanager (or the renamed cache manager name ), point to
      New , and click Custom
      cachestorage .

    2. In the attributes
      attribute section of the right panel, click the ellipsis (...).

    3. In the editablekeyvaluecollectioneditor
      dialog box, click Add to add a new name/value pair.

    4. In the right pane of the editablekeyvaluecollectioneditor dialog box, enter the key name and attribute value.

    5. Add more name/value pairs as appropriate, and click OK .

    6. (optional) in the name
      attribute section on the right panel of the configuration console, modify the name of the custom cache storage. The default name is cachestorage .

    7. In the type
      attribute section of the right panel, click the ellipsis. If the required type is not included in the Assembly folder, click
      typeselector
      loadassembly to find type assembly.

If you want to add another cache and manager instance, right clickCachemanagers
Node, pointingNewAnd then click
Cachemanager
, Repeat the previous steps. There can only be one default cache manager, and each cache manager must have a unique name.

Usage tips

The Configuration Setting of the cache application block affects the application's cache usage mode and its system environment, such as the amount of available memory. For example, if an application adds an entry that is much larger than the cache removed when it is cleared (this is a configuration setting) to the cache, the cache continues to grow. Over time, this will cause insufficient memory. Use the performance counters of the Application Block to help adjust configuration settings for each application.

Source mode used to cache application blocks

This topic lists the XML elements and attributes used to configure cache application blocks. You can manually edit XML data, but the Enterprise Library
The configuration console greatly simplifies this task. If you select to manually edit XML, the mode information used is included in this topic.

The configuration file contains the following section handler declarations.

 
<Configsections>
<Section name = "cachingconfiguration"
Type = "Microsoft. Practices. enterpriselibrary. caching. configuration. cachemanagersettings,
Microsoft. Practices. enterpriselibrary. caching, version = 3.1.0.0,
Culture = neutral, publickeytoken = NULL "/>
</Configsections>

The Section handler Declaration contains the name of the Configuration Setting section and the name of the section handler class for configuring data in the processing configuration section. The Configuration Setting section name is
CachingconfigurationThe name of the section handler class is
Microsoft. Practices. enterpriselibrary. caching. configuration. cachemanagersettings
.

Cachingconfiguration Element

Cachingconfiguration
The element specifies the configuration of the cache application block. This element is required.

Attributes and child elements

The following sections describeCachingconfiguration
The attributes and child elements of the element.

Attribute

Table 7.1 listsCachingconfiguration
The attribute of the element.

Table 7.1. Attributes of cachingconfiguration

Attribute Description
Defaultcachemanager If the application code is not created in the cache manager
Cachefactory

Provides a named instance of the cache manager, which is used by the cache application block. This attribute is required.



Encryptionproviders Element

EncryptionprovidersElement is
Cachingconfiguration
A child element of an element.Encryptionprovider
Elements list the encryption providers used by the backend storage. This element is optional.

ADD child element

AddElement isEncryptionproviders
A child element of an element.Add
Element to add the name of the encryption provider. This element is optional and can contain multipleAddElement.

Attribute

Table 7.2 listsAddThe attribute of the element.

Attributes of Table 7.2. Add

Attribute Description
Name The name of the encryption provider. The name must be unique in the Section. This attribute is required.
Type ImplementedIstorageencryptionprovider
The name of the API class. This attribute is required.



Backingstores Element

BackingstoresElement is
Cachingconfiguration
A child element of an element.Backingstores
Elements list the backend storage that can be used by the cache manager. If no backend storage is specified during configuration, the configuration console uses in-memory backend storage. This element is required.

ADD child element

AddElement isBackingstores
A child element of an element.AddElement to add the name of the backend storage. This element is required and can have multiple
AddElement.

Attribute

Table 7.3 listsAddThe attribute of the element.

Attributes of table 7.3. Add

Attribute Description
Name The name of the backend storage. This attribute is required.
Type Inherited fromBasebackingstore
The type name of the class. This attribute is required.
Encryptionprovidername The name of the encrypted provider, which must be unique in the Section. This attribute is optional.
Partitionname If you are using data cache storage, this attribute identifies the Database Section that the cache manager will use. If independent storage is used, it identifies the region where the cache manager will use independent storage. This attribute is required.
Databaseinstancename The name of the database instance. This attribute is necessary for back-end database storage.



Cachemanagers Element

CachemanagersElement is
Cachingconfiguration
A child element of an element.Cachemanagers
The elements list the cache manager. The cache manager indicates the cached instance used in the application. This element is necessary.

ADD child element

AddElement isCachemanagers
A child element of an element.AddElement to add the name of the cache manager. This element is optional and can contain multiple
AddElement.

Attribute

Table 7.4 listsAddThe attribute of the element.

Attributes of Table 7.4. Add

attributes description
name the name of the cache manager, which must be unique in the Section. This attribute is necessary.
expirationpollfrequencyinseconds set how long the background scheduler checks the timer for expired entries. This attribute must be a positive integer and necessary.
maximumelementsincachebeforescavenging set the maximum number of items that can be cached before cleanup starts. This attribute must be a positive integer and necessary.
numbertoremovewhenscavenging set the number of items removed at the beginning of clearing. This attribute must be a positive integer and necessary.
backingstorename this property is necessary.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.