开发者

Correct approach of setting up fluent nhibernate syscache with one table and four queries?

My scenario is pretty simple, I have 1 table with about 20 products that I would like to add to level 2 cache (SysCache) using Fluent NHibernate. I query this table 4 different ways so I figure I'd stick the whole thing in cache every so often and reduce the database hits.

My 4 queries are:

  1. All(start, max) for paging
  2. ByDate(date) for getting products before or after a certain date
  3. ById(id)
  4. ByName(name)

I have enabled SysCache in the fluent configuration using the code below and added the appropriate conf开发者_StackOverflow中文版iguration to web.config.

MsSqlConfiguration.MsSql2008.Cache(c => c.ProviderClass<SysCacheProvider>()
                                         .UseQueryCache())

I added the following code to the ProductMap

Cache.ReadWrite().Region("testregion");

Now how do I proceed from here? Do I have to add SetCachable(true) to all my 4 queries? Is that the correct approach?

Part of me thinks that there should be a way to cache an All() query and then point the 4 above queries to use the cached All() to query against. Maybe my assumptions are dead wrong and every query does need to be added to cache separately using SetCachable(true) on a query level.

What is the correct approach to setup cache for this case?

Thanks


Query caching is enabled individually. There are no shortcuts built-in.

Of course you could add an extension method, or use a base class that does that, but it's really not worth it: wholesale caching rarely improves the performance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜