Wednesday, April 13, 2011

What is the best cache for Nhibernate when using an MVC web app?

Hi,

if you were using Nhibernate for data access in an MVC app what would be the best cache provider e.g. Syscache,Syscache2,Memcache,HashTable.. to use?

Thanks for your opionions.

From stackoverflow
  • The best cache to use? Do you mean type of cache? Or cache platform?

    There is the HttpRuntime.Cache built in. Depends on your application for what to cache.

  • If you are asking about NHibernate's Cache Handling Methodology , (NHibernate don't store/retrieve cache data itself ,we need to configure cache provider seperately to do that)

    Due to the nature of Web Applications (Multi Threaded Application) , We can't use First Level Cache. But we can use

    • Second Level Cache
    • Query Cache

    While using cache , it may show old data, in following cases

    • When data is modified by different client, (other than ASP.Net client)
    • When data is modified by Triggers

    So, make sure to clear cache, when above cases exist.


    Regarding Cache Providers,

    Nhibernate support multiple cache providers, Syscache,Syscache2,Memcache,HashTable etc.. I use Syscache, and it works fine. Since i haven't worked on other cache providers, i can't compare them.

    Old and Only documentation for Nhibernate Caches http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/caches.html

    More Docs http://stackoverflow.com/questions/135776/best-place-for-nhibernate-documentation

  • HashTable is the default built-in cache provider. It is recommended not to use this one.

    • SysCache uses System.Web.Caching.Cache as the cache provider
    • SysCache2 is basically the same except it also supports SQL dependency-based expiration. It requires MSSQL 2000+.

    In most scenarios (non webfarm), the SysCache provider should be good enough.

    For more information check out the documentation on NHibernate.Caches

0 comments:

Post a Comment