Chapter 4 cache application blocks

Source: Internet
Author: User
Cache application Program Block Introduction

Enterprise Library
The cache application block allows developers to merge a local cache in an application. It supports in-memory caching and optional back-end storage that can be stored in a database or independently. The application block can be used without modification. It provides all required functions for obtaining, adding, and removing cached data. Configurable expiration and clearing policies are also part of the Application Block.

When building enterprise-wide applications, both the architecture and developers have to face many challenges. caching can help them overcome some of these challenges, including:

Performance

The cache uses the data stored by the user to close the corresponding data as much as possible to improve the performance of the application, which avoids the creation, processing and transmission of duplicate data.

Scalability

Storing information in the cache helps to save resources and improve scalability when application requirements increase.

Availability

By storing data in the cache, applications may survive system failures, such as network latency, Web service problems, and hardware errors.

Common scenarios

The cache application block applies to the following situations:

    • The statement data must be accessed repeatedly or rarely changed.

    • Data access is expensive during creation, access, or transmission.

    • Data must always be available, even when the source, such as the server is unavailable.

Cache application blocks can be used in the following application types:

    • Windows Forms

    • Console Application

    • Windows Services

    • COM + server

    • ASP. NET web applications or web services, if the required features are not included in the ASP. NET cache.

The cache application block is deployed in an independent application domain. Each application domain can have one or more caches, either with or without backend storage. The cache cannot be shared in different application domains.

The cache application block optimizes the performance and is thread-safe and exception-safe. You can expand it to include your expiration Policy and backend storage.

Example Application Code

The following code adds an entry to the cache and extracts an entry from the cache. It creates
Product
Type object, and then add it to the cache, there is also a purge priority of 2, a command that does not refresh the entry after the entry expires, and a 5-minute validity period starting from the last access of the entry.

Note:

Code not includedProductClass definition.

Example 7.1. C #

Cachemanager productscache = cachefactory. getcachemanager ();

String id = "productoneid ";
String name = "productxyname ";
Int price = 50;

Product = new product (ID, name, price );

Productscache. Add (product. productid, product, cacheitempriority. Normal, null, new slidingtime (timespan. fromminutes (5 )));

// Retrieve the item.
Product = (product) productscache. getdata (ID );


Example 7.2. Visual Basic. net

Dim productscache as cachemanager = cachefactory. getcachemanager ()

Dim ID as string = "productoneid"
Dim name as string = "productonename"
Dim price as integer = 50

Dim newproduct as product = new product (ID, name, price)

Productscache. Add (newproduct. productid, newproduct, cacheitempriority. Normal, nothing, new slidingtime (timespan. fromminutes (5 )))

'Retrieve the item.
Product = directcast (productscache. getdata (ID), product)



Reader requirements

This guide is intended for software architecture and software developers. To learn more about the benefits of this Guide, you must first understand the following technologies:

    • Microsoft Visual maxcompute 2005

    • Microsoft. NET Framework 2.0

Highlights of Enterprise Library cache application blocks

The Enterprise Library cache application block contains the following features:

    • You can use graphical tools and the named Enterprise Library configuration console to manage configuration settings.

    • You can configure a persistent storage location and use the standalone storage Enterprise Library.
      Data Access Application Block. Its status is synchronized with the cache in the memory.

    • You can use custom expiration policies and storage locations to expand application blocks.

    • Ensure that the Application Block is executed in the thread security manager.

System Requirements

The requirements for running cache application blocks are as follows:

    • Microsoft Windows XP Professional, Windows Server 2003, or
      Windows Vista

    • Microsoft. NET Framework 2.0

    • Microsoft Visual Studio 2005 Development System (Any of the following versions ):

      • Microsoft Visual maxcompute 2005 Standard Edition

      • Microsoft Visual maxcompute 2005 Professional Edition

      • Microsoft Visual Studio 2005 team edition for Software
        Developers

      • Microsoft Visual Studio 2005 team edition for Software
        Testers

      • Microsoft Visual Studio 2005 team edition for Software
        Architects

      • Microsoft Visual Studio 2005 team suite

Cache Application Block dependency

The cache application block depends on other code in the Enterprise Library:

Core library functions

The Enterprise Library Kernel provides services such as measurement and configuration.
The dependencies shared by the library Application Block. The features of the kernel library are included in the Assembly
Microsoft. Practices. enterpriselibrary. Common. dll
.

Objectbuilder Subsystem

Objectbuilder
The subsystem executes all the repetitive and necessary tasks for creating and destroying object instances, and provides high flexibility. Enterprise
LibraryObjectbuilder
Subsystems are used for tasks such as injecting a class configured to a program block and connecting a measurement class to an application block.
Objectbuilder
Subsystem is included in
Microsoft. Practices. objectbuilder. dll
Programs.

Data Access Application Block

If you use the database as the backend storage, you need to use this application block.

Encrypt application blocks

Use this application block to encrypt data in the cache.

The recommended method for modifying the configuration settings of cache application blocks is to use the Enterprise Library configuration console.

Cache Application Block documentation

In addition to introductory materials, the document also includes the following topics:

Use cached application blocks to develop applications

First explains how to configure the cache application block and add it to the application. Then explain how to use the application block to perform typical cache operations if backend storage is selected.

Design of cache application blocks

Explains the design decisions and related decisions of application blocks.

Extend and modify cache application blocks

Explains how to add your own backend storage and expiration policies to expand the application block, and explains how to modify the source code to change it.

Deployment and operations

Explains how to deploy and update an application block assembly.

Quick Start

Explains how to install and configure the Quick Start application, and includes a series of tutorials that demonstrate how to merge common cache operations into the application.

More information

For more information, see the following modes and practices:

    • Application
      Architecture for. Net: designing applications and
      Services

    • Caching
      Architecture guide for. NET Framework applications

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.