locked
AppFabric Cache + OData RRS feed

  • Question

  • Can I use AppFabric Cache to cache my OData service?

    What is the best caching practise for OData?

    How is it done?

    Saturday, October 30, 2010 6:15 AM

Answers

  • You can use AppFabric caching with any .NET application, so it should work with your OData service. Right now, you can use the released Windows Server AppFabric to cache data on-premises. We have recently announced the Windows Azure AppFabric Caching CTP. For a 3min video on Server + Azure caching see http://www.youtube.com/watch?v=_Tgb2Zxvd8s. Just note that the Azure version is not released yet.

    Depending on what you want to cache, you could improve performance in different ways. If you're consuming an OData service, then you could cache the results of OData queries to avoid having to make the same queries repeatedly in a short amount of time.

    If you're implementing the OData service, then you will want to cache the results returned to clients so that you can improve performance and reduce the demand on the database/other-datastore. However, there could be some complexities here. If you use the Entity Framework to setup your Data Service, then a lot of the hard work is done for you behind the scenes. Unfortunately, this means that it is harder to control when the caching happens in response to client requests. I haven't personally tried this, but it looks like one solution might be to use a sample that shows how to implement caching with Entity Framework: EF Caching with Jarek Kowalski's Provider  and Tracing and Caching for Entity Framework available on MSDN Code Gallery. This sample actually has an implementation that uses Velocity CTP 3 (Velocity was the codename for the pre-release version of Windows Server AppFabric Caching). So you'll have to update that code for the release. For example, the DataCacheFactory class constructor now takes a DataCacheFactoryConfiguration object instead of multiple parameters. But you can find the necessary changes in numerous examples in the documentation and on the web. A good place to start is here: Preparing the Cache Client Development Environment (Windows Server AppFabric Caching).

    Note that if you are not using Entity Framework and are manually creating a feed from a non-relational data source, then you have complete control to use AppFabric Caching programmatically in any way that makes sense for your app.

    The basic steps are: find some machines, install AppFabric on them, configure the caching service, reference the AppFabric cache client assemblies in your project, configure your app to point to the cache cluster, and then make programmatic caching API calls (or use the web.config for ASP.NET applications).

    Also, look at this other forum post for a different caching strategy using the browser capabilities: http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/thread/98966f80-144d-4599-ab00-716e2596a2ca/. It seems like you have more control over the caching strategy by using AppFabric. AppFabric caching is also server-side and not browser-dependent.

    I'm wondering whether ASP.NET output caching would help here, but I need to research more. Perhaps someone else on the forum will respond from their experiences with it or other caching strategies.

    I hope this helps. Thanks.

    Jason Roth

    Tuesday, November 2, 2010 7:05 PM

All replies

  • You can use AppFabric caching with any .NET application, so it should work with your OData service. Right now, you can use the released Windows Server AppFabric to cache data on-premises. We have recently announced the Windows Azure AppFabric Caching CTP. For a 3min video on Server + Azure caching see http://www.youtube.com/watch?v=_Tgb2Zxvd8s. Just note that the Azure version is not released yet.

    Depending on what you want to cache, you could improve performance in different ways. If you're consuming an OData service, then you could cache the results of OData queries to avoid having to make the same queries repeatedly in a short amount of time.

    If you're implementing the OData service, then you will want to cache the results returned to clients so that you can improve performance and reduce the demand on the database/other-datastore. However, there could be some complexities here. If you use the Entity Framework to setup your Data Service, then a lot of the hard work is done for you behind the scenes. Unfortunately, this means that it is harder to control when the caching happens in response to client requests. I haven't personally tried this, but it looks like one solution might be to use a sample that shows how to implement caching with Entity Framework: EF Caching with Jarek Kowalski's Provider  and Tracing and Caching for Entity Framework available on MSDN Code Gallery. This sample actually has an implementation that uses Velocity CTP 3 (Velocity was the codename for the pre-release version of Windows Server AppFabric Caching). So you'll have to update that code for the release. For example, the DataCacheFactory class constructor now takes a DataCacheFactoryConfiguration object instead of multiple parameters. But you can find the necessary changes in numerous examples in the documentation and on the web. A good place to start is here: Preparing the Cache Client Development Environment (Windows Server AppFabric Caching).

    Note that if you are not using Entity Framework and are manually creating a feed from a non-relational data source, then you have complete control to use AppFabric Caching programmatically in any way that makes sense for your app.

    The basic steps are: find some machines, install AppFabric on them, configure the caching service, reference the AppFabric cache client assemblies in your project, configure your app to point to the cache cluster, and then make programmatic caching API calls (or use the web.config for ASP.NET applications).

    Also, look at this other forum post for a different caching strategy using the browser capabilities: http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/thread/98966f80-144d-4599-ab00-716e2596a2ca/. It seems like you have more control over the caching strategy by using AppFabric. AppFabric caching is also server-side and not browser-dependent.

    I'm wondering whether ASP.NET output caching would help here, but I need to research more. Perhaps someone else on the forum will respond from their experiences with it or other caching strategies.

    I hope this helps. Thanks.

    Jason Roth

    Tuesday, November 2, 2010 7:05 PM
  • Thanks for a very thorough answer!

    Yes, I'm using Azure AppFabric Caching CTP and I wan't to cache the response of my REST service (WCF Data Services) like how ASP.NET output caching works. It would be very appretiated to see an example of how to accomplish this.

    (I am using EF but I'm hesitant to cache the data layer ATM)

    Thanks.

    Martin

     

    Wednesday, November 3, 2010 4:33 PM
  • Peter Qian has published an interesting post about using ASP.NET output caching with a WCF Data Service:

    http://blogs.msdn.com/b/peter_qian/archive/2010/11/17/using-asp-net-output-caching-with-wcf-data-services.aspx

    Hope that helps,

    Glenn Gailey


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Monday, January 24, 2011 8:49 AM