OEA framework learning: Cache

Source: Internet
Author: User
I. Summary

I have been learning OEA for a while, and I am still familiar with it from the perspective of the whole. Let's first look at the cache module design in OEA that the author thinks, and read the author'sArticleTo consolidate what we have learned, we are here to readCodeTo improve programming thinking.

 

Ii. Technical Background

 

Design Points: find common points and change points of functions.

Commonalities:

Cache allows you to quickly obtain data stored in the memory. When data is accessed again, the application obtains data from the cache instead of the original data source. This can improve performance and scalability. In addition, when the data source is temporarily unavailable, the cache makes the data available.

Change Point.

The most important change in cache design is the update policy (Expiration Policy ).

Common update policies include real-time detection, heartbeat detection, cache dependency detection, absolute expiration, and sliding expiration. Of course, in the ApplicationProgramDesigning,

A general cache framework, the specific cache location is also a common change point, such as memory, files, databases, networks, and clouds.

In the specific design, pay attention to these two changes.

Knowledge points to use:

Decoration Mode

The architecture of the. net4.0 Scalable Cache System. runtime. caching

System. runtime. caching class diagram:

The core of the Code is objectcache (Cache container)

The memorycache class is a memory cache that implements the objectcache class. You can use it to complete most of the work.

The prototype of the memorycache class is defined in the ASP. NET cache object in the system. Web. caching space. Therefore, the internal cache logic is similar to the cache logic provided by the early ASP. NET.

Abstract base classes provide the following functions:

    • Create and manage caches.
    • Specify expiration and revocation.
    • This event is triggered when the cache information changes.

Changemonitor provides a base class for derived custom types used to monitor the status changes of the data that the cache items depend on

Sqlchangemonitor monitors changes to the SQL Server database

Hostfilechangemonitor monitors directories and file paths, and notifies the cache of changes to monitored items

Filechangemonitor indicates the object used to monitor changes to the file.

Create your own cache provider:

    • Create a class that inherits objectcache and provides custom cache implementation.
    • Create a class that integrates memorycache and provides custom cache implementation.
    • Create a class that inherits outputcacheprovider and configure the application to use this custom output cache provider.

Iii. OEA Cache

the General cache module OEA uses the. net.4.0 Scalable Cache System. runtime. caching

code structure of the General cache framework:

the cache provider structure is as follows: modifier mode

hybirdcacheprovider combined memorycache (primary cache: Memory) and diskcache (secondary cache: Hard Disk)

four internal cacheproviders are implemented:

  1. sqlcompactprovider: because local caching is required on the client, the cache provider mainly implements sqlcompact for storage.
  2. memcachedprovider: you may need to use distributed cache for storage.
  3. memorycacheprovider: This is an implementation integrating the system. runtime. caching. objectcache class in. net4.0. Memorycache does not support region. Therefore, the regioncache class is added here to perform a proxy for memorycache to support the cache of partitions.
  4. twolevelprovider: A second-level cache implemented in decoration mode. For example, we can use memory + sqlcompact on the client for level-2 cache.
  5. decorator mode:

    1. You need to extend the functions of a class, or add additional responsibilities to a class.

    2. You need to dynamically add functions to an object . These functions can be dynamically revoked.

    3. A large number of functions are generated by the arrangement of some basic functions combination to make the inheritance relationship unrealistic.

    4. When the subclass generation method cannot be used for expansion. One case is that there may be a large number of independent extensions. To support each combination, a large number of subclasses will be generated, resulting in explosive growth of the number of subclasses. Another scenario is that the class definition is hidden, or the class definition cannot be used to generate a subclass.

  • Iv. Use Cache

     

    Test Cases

     
    1:[Testmethod]
     
    2:Public voidTestcache ()
    3:{
     
    4:CacheMemorydisk =NewCache(NewMemorycacheprovider());
    5:Memorydisk. Add ("Test","Klmg",NewPolicy());
     
    6:}
    7: 

     

     

  • 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.