Current filter:
                                You should refresh the page.
                                  • Session layer caching
                                    By default, XPO caches records at the Session level. Since most XAF root Views have their own Session, each root View has its own cache. This cache is reset when a View is closed or its Object Space is reloaded. Besides, most database systems provide an advanced caching mechanism and perform the subsequent calls of the same SQL queries faster. In most situations, this functionality is enough to achieve good performance. In case of a significant latency of a database server connection and a lot of repetitive queries, it may be helpful to implement caching at the data store level.

                                    Data layer caching
                                    To enable data store-level caching, connect an application to a Cached Data Store. In this case, the application caches database queries and their results. If an application executes the same query for a second time, the cached data will be loaded from memory. The DataCacheNode and DataCacheNodeLocal objects perform caching. Connect these objects to a shared DataCacheRoot object. DataCacheRoot synchronizes changes made in different cache nodes. Thus, you can connect only one root to the database at one time. You need to pass all data modifications through it.

                                    Ways to share DataCacheRoot to implement data layer caching
                                    Depending on your XAF application configuration, consider the following options:

                                    1. Middle Tier server application
                                    In this configuration, DataCacheRoot is hosted on a Middle Tier server application. Each client application's instance is connected to it. To host DataCacheRoot on your Middle Tier server application, update the following code in the YourSolutionName.ApplicationServer project's Program.cs (Program.vb) or ApplicationServerService.cs (ApplicationServerService.vb) file:

                                    [C#]
                                    var mainDataStore = XpoDefault.GetConnectionProvider(connectionString, AutoCreateOption.SchemaAlreadyExists); var root = new DataCacheRoot(mainDataStore); var node = new DataCacheNode(root); Func<IDataLayer> dataLayerProvider = () => new ThreadSafeDataLayer(XpoTypesInfoHelper.GetXpoTypeInfoSource().XPDictionary, node); WcfXafServiceHost serviceHost = new WcfXafServiceHost(dataLayerProvider, dataServerSecurityProvider, false);
                                    [VB.NET]
                                    Dim mainDataStore = XpoDefault.GetConnectionProvider(connectionString, AutoCreateOption.SchemaAlreadyExists) Dim root = New DataCacheRoot(mainDataStore) Dim node = New DataCacheNode(root) Dim dataLayerProvider As Func(Of IDataLayer) = Function() New ThreadSafeDataLayer(XpoTypesInfoHelper.GetXpoTypeInfoSource().XPDictionary, node) Dim serviceHost As WcfXafServiceHost = New WcfXafServiceHost(dataLayerProvider, dataServerSecurityProvider, False)


                                    2. ASP.NET server application

                                    To do this in your ASP.NET application. Create the CachedDataStoreProvider.cs (CachedDataStoreProvider.vb) file in the YourSolutionName.Web project:

                                    [C#]
                                    using System; using System.Data; using DevExpress.ExpressApp.Xpo; using DevExpress.Xpo.DB; namespace YourSolutionName.Web { public class CachedDataStoreProvider : IXpoDataStoreProvider { private static IDisposable[] rootDisposableObjects; private static DataCacheRoot root; private static IXpoDataStoreProvider xpoDataStoreProvider; public static void ResetDataCacheRoot() { root = null; if (rootDisposableObjects != null) { foreach (IDisposable disposableObject in rootDisposableObjects) { disposableObject.Dispose(); } rootDisposableObjects = null; } } public string ConnectionString { get { return xpoDataStoreProvider.ConnectionString; } } public CachedDataStoreProvider(string connectionString, IDbConnection connection, bool enablePoolingInConnectionString) { if (xpoDataStoreProvider == null) { xpoDataStoreProvider = XPObjectSpaceProvider.GetDataStoreProvider(connectionString, connection, enablePoolingInConnectionString); } } public IDataStore CreateWorkingStore(out IDisposable[] disposableObjects) { if (root == null) { IDataStore baseDataStore = xpoDataStoreProvider.CreateWorkingStore(out rootDisposableObjects); root = new DataCacheRoot(baseDataStore); } disposableObjects = new IDisposable[0]; return new DataCacheNode(root); } public IDataStore CreateUpdatingStore(bool allowUpdateSchema, out IDisposable[] disposableObjects) { return xpoDataStoreProvider.CreateUpdatingStore(allowUpdateSchema, out disposableObjects); } public IDataStore CreateSchemaCheckingStore(out IDisposable[] disposableObjects) { return xpoDataStoreProvider.CreateSchemaCheckingStore(out disposableObjects); } } }
                                    [VB.NET]
                                    Imports System Imports System.Data Imports DevExpress.ExpressApp.Xpo Imports DevExpress.Xpo.DB Public Class CachedDataStoreProvider Implements IXpoDataStoreProvider Private Shared rootDisposableObjects As IDisposable() Private Shared root As DataCacheRoot Private Shared xpoDataStoreProvider As IXpoDataStoreProvider Public Shared Sub ResetDataCacheRoot() root = Nothing If rootDisposableObjects IsNot Nothing Then For Each disposableObject As IDisposable In rootDisposableObjects disposableObject.Dispose() Next rootDisposableObjects = Nothing End If End Sub Private ReadOnly Property IXpoDataStoreProvider_ConnectionString As String Implements IXpoDataStoreProvider.ConnectionString Get Return xpoDataStoreProvider.ConnectionString End Get End Property Public Sub New(ByVal connectionString As String, ByVal connection As IDbConnection, ByVal enablePoolingInConnectionString As Boolean) If xpoDataStoreProvider Is Nothing Then xpoDataStoreProvider = XPObjectSpaceProvider.GetDataStoreProvider(connectionString, connection, enablePoolingInConnectionString) End If End Sub Private Function IXpoDataStoreProvider_CreateWorkingStore(ByRef disposableObjects() As IDisposable) As IDataStore Implements IXpoDataStoreProvider.CreateWorkingStore If root Is Nothing Then Dim baseDataStore As IDataStore = xpoDataStoreProvider.CreateWorkingStore(rootDisposableObjects) root = New DataCacheRoot(baseDataStore) End If disposableObjects = New IDisposable(-1) {} Return New DataCacheNode(root) End Function Private Function IXpoDataStoreProvider_CreateUpdatingStore(allowUpdateSchema As Boolean, ByRef disposableObjects() As IDisposable) As IDataStore Implements IXpoDataStoreProvider.CreateUpdatingStore Return xpoDataStoreProvider.CreateUpdatingStore(allowUpdateSchema, disposableObjects) End Function Private Function IXpoDataStoreProvider_CreateSchemaCheckingStore(ByRef disposableObjects() As IDisposable) As IDataStore Implements IXpoDataStoreProvider.CreateSchemaCheckingStore Return xpoDataStoreProvider.CreateSchemaCheckingStore(disposableObjects) End Function End Class


                                    After that, update the following code in the WebApplication.cs (WebApplication.vb) file:

                                    [C#]
                                    using System; using DevExpress.ExpressApp; using DevExpress.ExpressApp.Web; using DevExpress.ExpressApp.Xpo; using DevExpress.ExpressApp.Security; using DevExpress.ExpressApp.Security.ClientServer; namespace YourSolutionName.Web { public partial class YourSolutionNameAspNetApplication : WebApplication { //... private IXpoDataStoreProvider GetDataStoreProvider(string connectionString, System.Data.IDbConnection connection) { System.Web.HttpApplicationState application = (System.Web.HttpContext.Current != null) ? System.Web.HttpContext.Current.Application : null; IXpoDataStoreProvider dataStoreProvider = null; if (application != null && application["DataStoreProvider"] != null) { dataStoreProvider = application["DataStoreProvider"] as IXpoDataStoreProvider; } else { dataStoreProvider = new CachedDataStoreProvider(connectionString, connection, true); if (application != null) { application["DataStoreProvider"] = dataStoreProvider; } } return dataStoreProvider; } //... } }
                                    [VB.NET]
                                    Imports System Imports DevExpress.ExpressApp Imports DevExpress.ExpressApp.Web Imports DevExpress.ExpressApp.Xpo Imports DevExpress.ExpressApp.Security Imports DevExpress.ExpressApp.Security.ClientServer Partial Public Class Solution2AspNetApplication Inherits WebApplication '... Private Function GetDataStoreProvider(ByVal connectionString As String, ByVal connection As System.Data.IDbConnection) As IXpoDataStoreProvider Dim application As System.Web.HttpApplicationState = If((System.Web.HttpContext.Current IsNot Nothing), System.Web.HttpContext.Current.Application, Nothing) Dim dataStoreProvider As IXpoDataStoreProvider = Nothing If Not application Is Nothing AndAlso application("DataStoreProvider") IsNot Nothing Then dataStoreProvider = TryCast(application("DataStoreProvider"), IXpoDataStoreProvider) Else dataStoreProvider = New CachedDataStoreProvider(connectionString, connection, True) If Not application Is Nothing Then application("DataStoreProvider") = dataStoreProvider End If End If Return dataStoreProvider End Function '... End Class


                                    Finally, update the following code in the Global.asax file:

                                    [C#]
                                    using System; using System.Configuration; using DevExpress.ExpressApp; using DevExpress.Persistent.Base; using DevExpress.ExpressApp.Security; using DevExpress.ExpressApp.Web; using DevExpress.Web; namespace YourSolutionName.Web { public class Global : System.Web.HttpApplication { //... protected void Application_End(Object sender, EventArgs e) { CachedDataStoreProvider.ResetDataCacheRoot(); } //... } }
                                    [VB.NET]
                                    Imports System Imports System.Configuration Imports DevExpress.ExpressApp Imports DevExpress.Persistent.Base Imports DevExpress.ExpressApp.Security Imports DevExpress.ExpressApp.Web Imports DevExpress.Web Public Class [Global] Inherits System.Web.HttpApplication '... Protected Sub Application_End(ByVal sender As Object, ByVal e As EventArgs) CachedDataStoreProvider.ResetDataCacheRoot() End Sub '... End Class

                                     
                                    See Also
                                    1. How to measure and improve the application's performance - check other ways of improving the application's performance before using these solutions. Note that they may increase the memory used by your applications.
                                    2. Session Management and Caching - check out this blog post for more information on built-in XPO caching strategies and their differences.

                                Show all comments
                                • Warren Connors 4 01.13.2016

                                  3 questions:  1) When this is done, it affects ALL database access against ALL tables?  2) Do you have a code example like above for the XAF web application?  3) Do you have a full XAF web application example solution?

                                • Dennis (DevExpress Support) 01.14.2016

                                  Hello Warren,

                                  To process your recent post more efficiently, I created a separate ticket on your behalf: T334279: XPO caching at the data store level for XAF Web app. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

                                • ASM 07.23.2016
                                  Dennis,

                                  could you please make the T334279 Ticket public?

                                  Thank you!
                                • Dennis (DevExpress Support) 07.24.2016
                                  @Hurzi!: No, I cannot, because it was marked as Private by its owner. I can repost my answer from this ticket, though:

                                  >>3 questions:  1) When this is done, it affects ALL database access against ALL tables?  2) Do you have a code example like above for the XAF web application?  3) Do you have a full XAF web application example solution?
                                  "A1: Yes. You can configure this via the Cross-Platform Core Libraries > DevExpress.Xpo.DB.Helpers > DataCacheConfiguration class.
                                  A2-3: No, but it will differ from the WinForms example only by inheritance from the WebApplication class. I have updated the How to use XPO caching in XAF article so it will be easier to follow. "

                                  If you experience any further difficulties with this article, please use the https://www.devexpress.com/Support/Center/Question/Create service to submit separate tickets for each problem/question you require our assistance with.
                                • Giuseppe Ascione 12.21.2016
                                  I support,
                                  I'm using the DataCacheRoot lik e Dan explained and it work well for multiuser, but there is a problem. Sometimes some batch procedure update or import data directly to my database. In this case I want to Invalidate the cache.

                                  i have tried to call the ResetDataCacheRoot method and also the  root.NotifyDirtyTables( DataCacheCookie.Empty, "Customers", "orders", "etc...") ... But the cache on 90% of the test do not invalidate. I can try to call the reset cache many times, but the cache persist e the data will not refreshed.

                                  Can you please help me?
                                  Thanks
                                • Dennis (DevExpress Support) 12.21.2016

                                  @Giuseppe: We will be more than happy to research your particular situation and look for the best technical solutions if you provide us with your debuggable project along with the test database and exact repro instructions. Please use the https://www.devexpress.com/Support/Center/Question/Create service to submit this information in a separate ticket so that we can start working on it right away.

                                • Fabio Scarvaglieri 05.08.2017
                                  Is also Reset of small part of Cache possible, so that don't have to load all the things after changes?

                                  e.g. this method:
                                  [C#]
                                  public static void ResetDataCacheRootByType<T>() where T : IDisposable { if (rootDisposableObjects != null) { foreach (var disposableObject in rootDisposableObjects.OfType<T>()) disposableObject.Dispose(); rootDisposableObjects = null; } }


                                • Fabio Scarvaglieri 05.08.2017
                                  How can I reset it, so changed data will be force loaded then?

                                  tried this:

                                  [C#]
                                  private void SaveAction_Execute(object sender, SimpleActionExecuteEventArgs e) { CachedDataStoreProvider.ResetDataCacheRoot(); }

                                  but get that exception:

                                  [C#]
                                  The error occurred: Type: InvalidOperationException Message: Die ConnectionString-Eigenschaft wurde nicht initialisiert. Data: 0 entries Stack trace: bei System.Data.SqlClient.SqlConnection.PermissionDemand() bei System.Data.SqlClient.SqlConnectionFactory.PermissionDemand(DbConnection outerConnection) bei System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) bei System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) bei System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) bei System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)



                                • Dennis (DevExpress Support) 05.08.2017

                                  @Fabio: I've created a separate ticket on your behalf (T512428: Questions about resetting data store cache for certain types only). It has been placed in our processing queue and will be answered shortly.

                                • Maximilian Kaya 08.25.2017
                                  Hi Dennis,
                                  does this works also for multi module(multi database) xaf apps?
                                  any sample for this scenario?
                                  Best regards
                                  Max
                                • Maximilian Kaya 08.25.2017
                                  to be exactly, multi database xaf apps impemented like E4896 
                                • Anatol (DevExpress Support) 08.25.2017

                                  Hello Maximilian,

                                  I have created a separate ticket for your question: T549157: How to use XPO caching when the application can be connected to multiple databases. We will answer you there soon.

                                • Jason Truong (https://yousoft.vn) 10.21.2017
                                  Hi team,

                                  I have some questions regarding this solution.
                                  1. Is there any way to cache only for specific object types?
                                  2. In a xaf winform example, I tried creating new object. The new object is still listed in the list view. I thought it doesn't work. I imagined that, the list items doesn't change after creating new object. Is it correct?

                                  regards,


                                • Scott Gross 10.21.2017
                                  Could we use this approach to to host the DB in Azure and still get acceptable performance? I would think a cache node in Azure and then another locally for the WinApp to connect?

                                  t‍hen if we have the web and mobile apps in Azure as well, would these connect to the cache node or directly to DB?
                                • Anatol (DevExpress Support) 10.23.2017

                                  Hell Jason, Scott.

                                  I have created separate tickets for your questions:

                                  Jason:
                                  Is there any way to cache only for specific object types?

                                  Creating a new object with XPO caching enabled

                                  Scott:
                                  Using XPO caching with Azure


                                  They have been placed in our processing queue. Our team will answer them soon.

                                • Farooq 10.26.2017
                                  Hi Anatol,

                                  I am using a SecuredObjectSpaceProvider as shown in below code, is it possible to cached that without breaking the existing functionality of my code. If yes, then can you please show me how.

                                  [C#]
                                  protected override void CreateDefaultObjectSpaceProvider(CreateCustomObjectSpaceProviderEventArgs args) { SecuredObjectSpaceProvider provider = new SecuredObjectSpaceProvider((ISelectDataSecurityProvider)Security, GetDataStoreProvider(args.ConnectionString, args.Connection)); args.ObjectSpaceProviders.Add(provider); } private IXpoDataStoreProvider GetDataStoreProvider(string connectionString, System.Data.IDbConnection connection) { System.Web.HttpApplicationState application = (System.Web.HttpContext.Current != null) ? System.Web.HttpContext.Current.Application : null; IXpoDataStoreProvider dataStoreProvider = null; if (application != null && application["DataStoreProvider"] != null) { dataStoreProvider = application["DataStoreProvider"] as IXpoDataStoreProvider; } else { dataStoreProvider = XPObjectSpaceProvider.GetDataStoreProvider(connectionString, connection, true); if (application != null) { application["DataStoreProvider"] = dataStoreProvider; } } return dataStoreProvider; }

                                • Uriah (DevExpress Support) 10.27.2017

                                  Hi Mohammed,

                                  I've created a separate ticket on your behalf (T569578: Is it possible to use XPO caching with the SecuredObjectSpaceProvider). It has been placed in our processing queue and will be answered shortly.

                                0 Solutions

                                Creation Date Importance Sort by