. Net Pet Shop 4 Study II: data layer (DAL) analysis (II)

Source: Internet
Author: User

Data Layer personalized Configuration

It is easy to know that in pet shop 4, the customer's personalized configuration function is also designed in the factory mode, so its structure and ideas are similar to the data access function in Dal.

The following table lists the files related to personalized Configuration:

Project name File Name Class (Interface) Name Description
Profiledalfactory     Factory
  Dataaccess. CS Dataaccess Decide which class to instantiate based on the profile project in the profiledal node in the web. congif file to complete the personalized configuration function.
Iprofiledal     Interface
  Ipetshopprofileprovider. CS Ipetshopprofileprovider Define all the methods required for personalized Configuration
Sqlprofiledal      
  Petshopprofileprovider. CS Petshopprofileprovider For sqlserver databases, inherit from the ipetshopprofileprovider interface and implement all of its methods
Oracleprofiledal      
  Petshopprofileprovider. CS Petshopprofileprovider Inherits from the ipetshopprofileprovider interface for Oracle databases and implements all of its methods.
Profile     Its specific functions are unknown (further research is required)
  Petshopprofileprovider. CS Petshopprofileprovider * I don't know what the class has to do with the above classes (interfaces ).
Xxxx     Xxxx
  Xxxx Profileprovider * The petshopprofileprovider class in the profile project inherits this class, but I do not know the source of this class, and I do not know anything about the access class.

Note: The mark * above is to be further studied. If you have any well-known friends, please let me know.

Data Layer cache dependency

Cache dependency: when the data cached locally by the user changes on the database (server) side, the database can notify the user of the local cache, this allows the local cache to re-read new data into the cache to synchronize the cached data with the actual data of the database, which can greatly improve the database access performance.

It is worth noting that only the SQL server data cache processing class is provided in petshop4: sqlcachedependency class.

The cache dependency here also adopts the factory mode.

Project name File Name Class (Interface) Name Description
Icachedependency     Interface on which the cache depends
  Ipetshopcachedependency. CS Ipetspopcachedependency Create a cache instance and return an aggregatecachedependency class to monitor dependencies. If the dependency object changes, remove the object from the cache and read the new Cache version.
Tablecachedependency     Implementation of cache Dependencies
  Tabledependency. CS Tabledependency Use cachedatabasename and configkey in the web. config file to determine the database and key value (table) to be cached and add it to the cache.
  Product. CS, item. CS, category. CS Product, item, category It inherits from the tabledependency class and provides the database table name parameters for the parent class.
Cachedependencyfactory     Factory
  Dependencyaccess. CS Dependencyaccess Determine the cachedependencyassembly project in the web. config file and return the cache instance
  Dependencyfacade. CS Dependencyfacade This class is actually called by the user and is used to encapsulate complex calls. It provides only a few simple getcategorydependency (), getproductdependency (), getitemdependency () methods, to call the dependencyaccess class.

Implementation Mechanism of cache dependency

To implement cache dependency, you must know the two main elements: first, how does the DBMS know which database needs cache dependency, and second, how does the applicationProgramHow to know which database and table has been cached.

To solve the first problem, register the database cache dependency on the DBMS. Use the Database Registration Tool aspnet_regsql to register the database. In the command line status:

Aspnet_regsql-s localhost-u mspetshop-P pass @ word1-D mspetshop4-et-T catagory

The parameters are described as follows:

Parameter Name Description
-S Server Name
-U Login Name
-P Logon User Password
-E Verify with Windows
-T Cache dependency on which table
-D Which database is dependent on the cache?
-Ed Allow cache dependency on Data
-Dd Disable cache dependency on users
-Et Allows cache dependency on a table
-Dt Disable cache dependency on a table
-Lt List tables on which cache dependencies are used

In petshop4, The aspnet_sqlcachetableforchangenotification table in the database mspetshop4 stores the cached dependent tables. The table content is as follows:

When the table content changes, the related stored procedures and triggers allow changeid to automatically add 1, and modify the cache table and obtain the information of the cache table. The related stored procedures are as follows:

stored procedure name description
aspnet_sqlcachepollingstoredprocedure notifies the application of table changes
aspnet_sqlcachequeryregisteredtablesstoredprocedure query the registered cache dependency table
aspnet_sqlcacheregistertablestoredprocedure register the cache table and add a trigger to the cache table to obtain changes to the cache table
aspnet_sqlcacheunregistertablestoredprocedure remove table cache dependencies
aspnet_sqlcacheupdatechangeidstoredprocedure when the table data changes, let changeid automatically add 1

We can see from the table above that the solution to the first problem is to notify through the storage process aspnet_sqlcachepollingstoredprocedure. Of course, the trigger is used to implement automatic notification.

The entire cache registration process can be expressed as follows:

Register the database cache dependency-> automatically add a cache table to the database-> automatically add a stored procedure-> Add a trigger to the stored procedure-> notify which table has changed through the trigger-> Update changeid.

In addition, you must configure in Web. config:

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.