XPO – 11.1 Sneak Peek – Data caching improvements

XPO Team Blog
21 April 2011


First, we would like to refresh your memory and return to the distant past and our old posts about data caching in XPO:

·        XPO is good for distributed applications

·        XPO Beta feature: SQLDependency support

Today is 2011, and we are excited to announce that in v2011 vol1, we greatly improved data caching support in XPO, and added additional functionality to it, allowing this feature to leave the “beta” state.

Want data caching via WCF Services? – Now, it’s easy!

In the previous blog, we already demonstrated how easy it is in 11.1 to create and use WCF Services for IDataStore. If you want to take advantages of XPO data caching using this solution, then the only difference is in using the ICachedDataStore interface and a respective base service class that implements this interface – CachedDataStoreService.

Let’s demonstrate it in action (the exact steps on how to add a data store service can be taken from the previous blog):

  1: using DevExpress.Xpo;
  2: using DevExpress.Xpo.DB;
  3: …
  4: public class Service1 : CachedDataStoreService {
  5:     public static ICachedDataStore MainDataStore;
  6:     static Service1() {
  7:         string connectionString = MSSqlConnectionProvider.GetConnectionString("localhost", "ServiceDB");
  8:         IDataStore dataStore = XpoDefault.GetConnectionProvider(connectionString, AutoCreateOption.DatabaseAndSchema);
  9:         MainDataStore = new DataCacheRoot(dataStore);
 10:     }
 11:     public Service1()
 12:         : base(MainDataStore) {
 13:     }
 14: }

Of course, some modifications of the service binding in the web.config file are necessary as well:

  1: <system.serviceModel>
  2:  <services>
  3:    <service name="WcfService1.Service1" behaviorConfiguration="WcfService1.Service1Behavior">
  4:      <!-- Service Endpoints -->
  5:      <endpoint address="" binding="basicHttpBinding" contract="DevExpress.Xpo.DB.ICachedDataStoreService">
  6:        <identity>
  7:          <dns value="localhost"/>
  8:        </identity>
  9:      </endpoint>
 10:    </service>
 11:  </services>
 12:  <behaviors>
 13:    <serviceBehaviors>
 14:      <behavior name="WcfService1.Service1Behavior">
 15:        <serviceMetadata httpGetEnabled="true"/>
 16:        <serviceDebug includeExceptionDetailInFaults="false"/>
 17:      </behavior>
 18:    </serviceBehaviors>
 19:  </behaviors>
 20: </system.serviceModel>

Fortunately, the client part does not need to be modified, because in our example, the service’s name did not change, and in addition, the “data caching domain” of our service is automatically detected by XPO.

Data caching configuration

After looking at how easy it is to implement, you may naturally ask how flexible it really is. Of course we did not forget about flexibility!

For example, it is possible for you to configure which tables need to be cached and which ones don’t. This option can be useful for tables, which are frequently changed – if they are changed a lot, it makes no sense to cache them. The code below demonstrates how the service above can be modified to configure the DataCacheRoot, to cache only the “Customer” table:

  1: using DevExpress.Xpo;
  2: using DevExpress.Xpo.DB;
  3: using DevExpress.Xpo.DB.Helpers;
  4: …
  5: public class Service1 : CachedDataStoreService {
  6:     public static ICachedDataStore MainDataStore;
  7:     static Service1() {
  8:         string connectionString = MSSqlConnectionProvider.GetConnectionString("localhost", "ServiceDB");
  9:         IDataStore dataStore = XpoDefault.GetConnectionProvider(connectionString, AutoCreateOption.DatabaseAndSchema);
 10:         DataCacheRoot dataCacheRoot = new DataCacheRoot(dataStore);
 11:         dataCacheRoot.Configure(
 12:             new DataCacheConfiguration(DataCacheConfigurationCaching.InList, "Customer")
 13:         );
 14:         MainDataStore = dataCacheRoot;
 15:     }
 16:     public Service1()
 17:         : base(MainDataStore) {
 18:     }
 19: }

Leveraging SQLDependency

Another configuration option for data caching we would like to tell you about is using SqlDependency feature of MS SQL Server (see here for the background on that). Again, a modified service class demonstrates how this can be done:

  1: using DevExpress.Xpo;
  2: using DevExpress.Xpo.DB;
  3: using DevExpress.Xpo.DB.Helpers;
  4: …
  5: public class Service1 : CachedDataStoreService {
  6:     public static ICachedDataStore MainDataStore;
  7:     static Service1() {
  8:         string connectionString = MSSqlConnectionProvider.GetConnectionString("localhost", "ServiceDB");
  9:         MSSqlConnectionProvider dataStore = (MSSqlConnectionProvider)XpoDefault.GetConnectionProvider(
 10:             connectionString,
 11:             AutoCreateOption.DatabaseAndSchema
 12:         );
 13:         MainDataStore = (ICachedDataStore)MSSql2005SqlDependencyCacheRoot.CreateSqlDependencyCacheRoot(
 14:             dataStore,
 15:             new DataCacheConfiguration(DataCacheConfigurationCaching.InList, "Customer"),
 16:             out objectsToDispose
 17:         );
 18:     }
 19:     public Service1()
 20:         : base(MainDataStore) {
 21:     }
 22: }

That’s it for this blog. Do you like what you see? Please let us know with your comments!

And happy XPOingWinking smile, as always!;-)

Free DevExpress Products – Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We’ll be happy to follow-up.
Nate Laff
Nate Laff

Well this answers the question on if I'll move my XAF apps to use the WCF service. Yes. Yes I will :)

21 April 2011
Defacto Software
Defacto Software


What does this mean for the advice in www.devexpress.com/issue=Q95027 ?



22 April 2011
Slava D (DevExpress)
Slava D (DevExpress)

@M. Brekhof:

This advice remains valid when using SqlDependency on the client. We still suggest using SqlDependency only on the server side in a scenario shown above. Because in other scenarios with a lot of clients, it will be very heavy for SQL Server and may lead to significant decrease of performance.

22 April 2011

Great !

Can the cache be persist on the client and re-used (loaded from a file on the client) on the next application startup ?

A lot of not-changing lookup table slow down application startup in my scenario ...

Maybe not out-of the box, but there is a way to archive this ?

Thanks and great work !


22 April 2011
Dusan Pupis
Dusan Pupis

What about data compression. It would come handy for slower connections, like 3G?

22 April 2011
Slava D (DevExpress)
Slava D (DevExpress)

@Luca Poretti:

I am afraid that the current implementation of data cache does not have such opportunities, because the "DataCacheNode" resets all cached data, when an instance of the "DataCacheRoot" is changed.

@Dusan Pupis:

For the purpose of compressing data you have all power of the WCF technology. There are many ways to implement such binding.

I suggest that you refer to the social.msdn.microsoft.com/.../5c67b0da-9e50-4ee1-b7ac-a4733c580980 forum topic, where this problem is discussed.

22 April 2011
Gustavo Marzioni
Gustavo Marzioni

Can you bring an example of this using XAF?

29 April 2011
Dennis (DevExpress)
Dennis Garavsky (DevExpress)


Check my answer to Martin in community.devexpress.com/.../100598.aspx

Please let me know if you need additional assistance on this. I will be glad to help you.

29 April 2011

In the two previous blog posts, we already described how to provide the IDataStore and ICachedDataStore

17 May 2011

If i want to bind in datagrid.

How to do it.

23 June 2011

Please login or register to post comments.