Extend and modify the cache application block of the Enterprise Library

Source: Internet
Author: User

In its original state, cache the applicationProgramBlocks work well in typical cache situations. However, you often have to customize certain behaviors of application blocks to better apply to specific environments of applications. There are two ways to customize: Extension and modification.

Extended Application Block

You can extend an application by specifying an extension point. Generally, you can customize a class that implements a specific interface or derives from an abstract class. Because custom classes exist in your application space, you do not need to modify or recreate the application block, but use configuration settings to specify the extension points.

You can extend the application block by adding a new backend storage type or a new expiration policy. For more information, see Add a new backend storage and add a new expiration policy.

Modify application blocks

You can changeSource codeTo modify the configuration. Because the modification is relative to the sourceCodeSo the Application Block must be rebuilt before the modification takes effect. You must also prepare for support and version release. For more information, see modify cache application blocks.

Add a new backend storage

To add a new backend storage, You can implementIbackingstore
Interface orBasebackingstore
The class inherited by the abstract class. You must ensure that the backend storage is still complete if an exception occurs during any operation to access the backend storage.

BecauseCache
To ensure that any backend storage is called in a single thread mode. This means that your implementation is not thread-safe.

Add a new expiration Policy

The cache application block allows you to add your own expiration policy. You can create a new class that implements the following interfaces to achieve this purpose:

Icacheitemexpiration

This interface allows developers to implement their own expiration mode. It is an application-defined managementCacheitem
Interface of the rule on how and when the object can expire.

Icacheitemrefreshaction

This interface Refreshes an expired cache entry.

Icacheitemrefreshaction
Interface defines the conventions for creating an object that must be implemented. This object refreshes the entry from the cache expiration. The implemented classes must be serializable. When implementing this interface, confirm that it only maintains the number of States required by its environment, because all the parts of the environment will be serialized, and too much State maintenance will lead to a huge object graph.

Modify cache application blocks

Cache application blocks are designed for caching various applications and General Purposes. extensions allow you to adapt to application blocks to meet the needs of any special application. However, if you want to add new features to the Application Block, you can modify its source code (the installer contains the source code and binary code ). In this case, it will be modified according to the following suggestions.

Suggestions for modifying cache application blocks

The following are the best practices for modifying source code:

    • Read the cache application block design section in the document to confirm that you understand how the Application Block works.

    • If the source code is significantly changed, or you want to use the custom version of the application block with the original version, consider changing the namespace of the cache application block. Note that modifying the namespace of an Application Block requires modifying the namespace of all other application blocks and applications that use cached application blocks.

    • use a strong name. Strong names can uniquely identify the Assembly, version, and verification integrity. This will have to generate your own key pair to sign the modified Application Block version. For more information, see the strong naming assembly and version guide. Another option is to select a custom version without signature, which can be referenced as a weak name.

    • to make the modification take effect, you must recompile the modified source code.

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.