Ticket T512428
Visible to All Users

Questions about resetting data store cache for certain types only

created 8 years ago

[DevExpress Support Team: CLONED FROM K18356: How to use XPO caching in XAF]
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; } }

How can I reset it, so changed data will be force loaded then?

tried this:

[C#]
but get that exception:

[C#]

Answers approved by DevExpress Support

created 8 years ago (modified 8 years ago)

Hello Fabio,

It is wrong to call the ResetDataCacheRoot method from an Action within a running application. That is because the "rootDisposableObjects" variable contains SqlConnection or similar IDbConnection objects for further removal at the application end (see the Application_End method). Since you are doing this with the live application, it expectedly fails when trying to perform subsequent database operations.

Instead, access a required DataCacheNode instance and call its NotifyDirtyTables method (the overload without the 'cookie' parameter) by passing table names as parameters. If you configured a shared DataCacheRoot in an ASP.NET application demonstrated at the end of the How to use XPO caching in XAF article, you can consider the following example code called from a ViewController:

C#
using DevExpress.Xpo.DB; using MainDemo.Module.BusinessObjects; using DevExpress.ExpressApp.Xpo; using DevExpress.Xpo.Helpers; ... DataCacheNode node = ((BaseDataLayer)((XPObjectSpace)Application.CreateObjectSpace(typeof(Contact))).Session.DataLayer).ConnectionProvider as DataCacheNode; if(node != null) { // Dropping cache for certain tables only. node.NotifyDirtyTables("Contact", "Note"); // Dropping entire cache. //node.Reset(); } ...

If this information does not help you, attach your debuggable test project and additionally, describe exactly why you decided to use caching at the data store level + why you might need to reset it for certain tables. This is a very advanced XPO feature, which is often misused by our customers, so I also want to make sure that you are on the right track with it.

    Comments (2)
    FS FS
    Fabio Scarvaglieri 8 years ago

      Hi,
      I have problems with data that is loaded and updated via ViewControllers when DataCacheNode is active.
      Data is sometimes old although it was changed already by another ViewController…

      So this was the reason to think about adding something like this… but hopefully there is a better way to use the performance of CacheData Node including the absolute correct / newest data…

      C#
      public class SaveViewController : ViewController { ModificationsController modController; public SaveViewController() { } protected override void OnActivated() { base.OnActivated(); modController = Frame.GetController<ModificationsController>(); if (modController != null) { modController.SaveAction.Execute += SaveAction_Execute; modController.SaveAndNewAction.Execute += SaveAction_Execute; modController.SaveAndCloseAction.Execute += SaveAction_Execute; } } protected override void OnDeactivated() { if (modController != null) { modController.SaveAction.Execute -= SaveAction_Execute; modController.SaveAndNewAction.Execute -= SaveAction_Execute; modController.SaveAndCloseAction.Execute -= SaveAction_Execute; } base.OnDeactivated(); } private void SaveAction_Execute(object sender, SimpleActionExecuteEventArgs e) { //CachedDataStoreProvider.ResetTypeCache(Application, ObjectSpace, View.ObjectTypeInfo.Type); } }

      Thx!

      Dennis Garavsky (DevExpress) 8 years ago

        Hello Fabio,

        >>
        I have problems with data that is loaded and updated via ViewControllers when DataCacheNode is active.
        Data is sometimes old although it was changed already by another ViewController…
        <<
        I am afraid it is difficult to provide any comments on this behavior without reproducing and debugging it locally. Would you please modify our MainDemo.Web app to demonstrate this behavior and provide us with the exact repro instructions? With that, we will be able to suggest the best technical solution or make sure there is no issue in the DevExpress code much faster. Thanks.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.