Some time ago, I wrote 《Ripple: When the generic method meets the abstract class-my "Memory Database" birthnotes", Recorded the design process of the PDF. Net memory database, and made some minor changes recently. It has been put into production and is currently running well. I looked at the source code again today and thought it was necessary to draw a structural diagram of the memory database, because the entireProgramCoreCodeWith detailed file comments, only 391 lines of code can be added. I am afraid I cannot understand the design idea of the entire program after a long time.
First, let's explain the architecture design issues:
(Pdf. Net memory database architecture)
Architecture Description
1. Core memdb
- A collection that stores all object classes, that is, memory data. The application needs to retrieve data by using the get <t> method (T is the object class type );
- If no memory data exists, call the load <t> method to load data from the PMDB object file;
- Call the Add <t> method when new object data needs to be saved;
- After the data is updated, if you want to save it, call the Save <t> method explicitly. Note that this method does not directly Save the data, it only saves this "method of saving data". For more information, see the description in the "moving flowers and trees" document;
- The background maintains a data writing thread and checks whether there is a "Data Storage Method" to be executed;
- Logs of data operations.
2. memdbengin
This class is actually a memdb factory class, which will generate a memdb object instance based on different database "paths;
The lifecycle of a memdb instance is managed by the "system cache". Here, the Cache Management object in system. runtime. caching of. Net 4.0 is used.
Because the system cache is used, memdb can "load on demand" and "Idle off.
Memory Data in a memdb instance corresponds to "system cache ".
3. icacheprovider cache Provider Interface
Defines a set of Cache Usage methods, you can specify a cache policy, such as relative expiration, absolute expiration, and so on.
4. cache provider
By default, the system cache implements memory cacheprovider, which is the memory cache provider. Due to the interface design, it can be theoretically expanded to a third-party "distributed cache ".
5. Data Persistence
The data used by the entire memory database is PDF. net object class. PDF is used here. the "serialization" and "deserialization" functions of the. NET Framework write memory data to PMDB files on the disk or load data from files to the memory.
6. user applications
Here is where "Memory Database" data is used. You can use multiple methods to operate memory data, such as directly using LINQ to object to query memory data or using PDF. net entityquery object to achieve two-way synchronization between the memory database and the database of the "relational database system" (DBMS. In actual use, you can discard the DBMS completely, and it is enough to use LINQ to object.
7. pdf. NET Entity object
This is the entity data used by the entire system, which is passed by the relevant components. Because PDF. the unique design of the net object class makes its serialization and deserialization efficiency very high. In addition, reflection is not used, and the performance is also very good, it does not have the "heavy" database of relational databases.MetadataIt is very lightweight and suitable for serving as the best carrier of memory database data.
System scalability
Looking at the design of the entire system, we can see that it has good scalability:
- Large applications-it can be easily expanded to support third-party distributed caching and build large-scale system applications;
- Small and Medium applications-common DBMS data can also be stored in memory databases to improve response capabilities;
- Lightweight micro-applications-you can discard DBMS completely and use a pure memory database to achieve the maximum response speed.
For details about the pdf. NET development framework, please refer to the official website http://www.pwmis.com/sqlmap
The memory database is currently in production and will be integrated into the next version of the PDF. NET Framework.