WCF: How to cache collections from OData in client

Viewed 898

Is there a possibility to cache a collection, retrieved using WCF from an OData service.

The situation is the following: I generated a WCF service client with Visual Studio 2015 using the metadata of the odata service. VS generated a class inheriting from System.Data.Services.Client.DataServiceContext. This class has some properties of type System.Data.Services.Client.DataServiceQuery<T>. The data of some of these properties change seldom. Because of performance reasons I want the WCF client to load these properties just the first time and not every time I use it in the code.

Is there a built in possibility to cache the data of these properties? Or can I tell the service client not to load specific proeprties newly every time.

Assuming the service client class is ODataClient and one of its properties is `Area, for now I get the values in the following way:

var client = new ODataClient("url_to_the_service");
client.IgnoreMissingProperties = true;

var propertyInfo = client.GetType().GetProperty("Area");
var area = propertyInfo.GetValue(client) as IEnumerable<object>;

The reason why I do this in such a complicated way is, that the client should be very generic: The properties to be handled can be configured in a configuration file.

* EDIT *

I already tried to find properties in the System.Data.Services.Client.DataServiceContext class or the System.Data.Services.Client.DataServiceQuery<T> class for the caching. But i wasn't able to find any.

1 Answers
Related