XAF uses the database access layer cache to improve performance and xaf Cache
In many cases, we can cache the database access layer to improve performance.
You can complete this task in the following steps:
1. Use custom XPObjectSpaceProvider
1.1.Create a customXPObjectSpaceProviderClass, which must be rewritten in the derived classCreateDataLayerMethod To createIDataLayerObject, connectDataCacheNode.
1.2.Make XAFXafApplication. CreateCustomObjectSpaceProvider event, or rewriteTheXafApplication. CreateDefaultObjectSpaceProviderVirtual method, file inYourSolutionName/WxxApplication. xxFile. Code is similar to this:
using DevExpress.ExpressApp.Xpo;using DevExpress.Xpo;using DevExpress.Xpo.DB;...public partial class SolutionWindowsFormsApplication : WxxApplication { //... protected override void CreateDefaultObjectSpaceProvider(CreateCustomObjectSpaceProviderEventArgs args) { args.ObjectSpaceProvider = new CachedObjectSpaceProvider(args.ConnectionString, args.Connection); }}...public class CachedObjectSpaceProvider : XPObjectSpaceProvider { public CachedObjectSpaceProvider(string connectionString, IDbConnection connection) : base(connectionString, connection) { } public CachedObjectSpaceProvider(string connectionString, IDbConnection connection, bool threadSafe) : base(connectionString, connection, threadSafe) { } protected override DevExpress.Xpo.IDataLayer CreateDataLayer(IDataStore workingDataStore) { DataCacheRoot cacheRoot = new DataCacheRoot(workingDataStore); DataCacheNode cacheNode = new DataCacheNode(cacheRoot); if (this.threadSafe) { return new ThreadSafeDataLayer(this.XPDictionary, cacheNode, new Assembly[0]); } return new SimpleDataLayer(this.XPDictionary, cacheNode); }}
The above text is translated according to the official English version. Here is the original text.
It should be noted that this cache can only be used in the web, or it will not work if you have multiple web servers connected to one DB.
If there are two WEB servers, A and B, when A modifies the data, server B does not know that the data in the database has been modified, so B still reads the data from the cache.
Similarly, the cache of the Win program is on the client computer, so there is a problem like the multi-WEB.
I searched for the official solution:
When SqlServer is used, you can use Service Broker to query the notification Service to notify the client. This is a direction. Because I want to consider compatibility, for example, I want to use this feature when using oracle or other libraries, so I didn't use this feature.
Query the Notification Service Introduction and official solution.
Of course, if your web application is only deployed on one server, you do not need to consider this issue.
In addition, the official website also provides another method:
2. Use CachedDataStoreService
Your application can connect to the data cache web services. You can see this link: How to create a data caching service that helps improve performance in distributed applications example.
To do this, you must specify a valid service (webservices or wcf) path in the XafApplication. ConnectionString attribute.
There are no cache updates for multiple servers or win instances in the 2nd methods. It feels better, but I have never tried it.
In addition, speaking of performance problems, I once encountered a win2008-win2012 than win7 development environment is much slower phenomenon, did N systems, after N days of experimental discovery, it turns out that these system power options are energy-saving by default. After being modified to high performance, the effect is remarkable.
See:
Session Management and Caching