Your SlideShare is downloading. ×
0
nHibernate Caching
nHibernate Caching
nHibernate Caching
nHibernate Caching
nHibernate Caching
nHibernate Caching
nHibernate Caching
nHibernate Caching
nHibernate Caching
nHibernate Caching
nHibernate Caching
nHibernate Caching
nHibernate Caching
nHibernate Caching
nHibernate Caching
nHibernate Caching
nHibernate Caching
nHibernate Caching
nHibernate Caching
nHibernate Caching
nHibernate Caching
nHibernate Caching
nHibernate Caching
nHibernate Caching
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

nHibernate Caching

5,876

Published on

Published in: Technology
1 Comment
5 Likes
Statistics
Notes
  • Nice and much briefed presentation about NHibernate. Juts need to mention that there is another cache provider called NCache which offers plug in for NHibernate and it is doing pretty good job for me.

    http://www.alachisoft.com/ncache/nhibernate_index.html
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
5,876
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
171
Comments
1
Likes
5
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. nHibernate Caching
    Albert Kuo
    1
  • 2. Database Transaction
    nHibernate Caching
    nHibernate Caching Implementation
    Reference
    2
    Agenda
  • 3. Database Transaction
    3
  • 4. Understanding database transactions
    4
  • 5. NHibernateITransaction API
    5
  • 6. NHibernateITransaction API
    6
  • 7. nHibernate Caching
    7
  • 8. Used for optimizing database applications.
    A cache is designed to reduce traffic between your application and the database by conserving data already loaded from the database.
    Database access is necessary only when retrieving data that is not currently available in the cache.
    The application may need to empty (invalidate) the cache from time to time if the database is updated or modified in some way, because it has no way of knowing whether the cache is up to date
    What is caching?
    8
  • 9. nHibernate Cache
    Persistence context cache
    Pluggable, scope is process or cluster
    9
  • 10. Two different Caches
    First-level cache
    Second-level cache
    associated with the Session object
    Hibernate uses first-level cache on a per transaction basis (within a single transaction boundary)
    Used mainly to reduce the number of SQL queries it needs to generate within a given transaction.
    For example, if an object is modified several times within the same transaction, Hibernate will generate only one SQL UPDATE statement at the end of the transaction, containing all the modifications
    associated with the SessionFactory object
    Second-level cache keeps loaded objects at the Session Factory level across transaction boundaries
    The objects in the second-level cache are available to the whole application, not just to the user running the query
    This way, each time a query returns an object that is already loaded in the cache, one or more database transactions potentially are avoided.
    10
  • 11. Use it when you need to cache actual query results, rather than just persistent objects
    Query-level Cache
    11
  • 12. nHibernate Caching Implementation
    12
  • 13. http://nhforge.org/media/p/6.aspx
    Where to download
    13
  • 14. How to configure?
    You have 3 DLLs need to be added into reference
    14
  • 15. How to configure ? – cont.
    Add two property into <session-factory>
    <!-- nHibernate Cache configuration -->
    <property name="cache.provider_class">NHibernate.Caches.Prevalence.PrevalenceCacheProvider, NHibernate.Caches.Prevalence</property>
    <property name="cache.use_query_cache">true</property>
    <property name="cache.use_second_level_cache">true</property>
    <property name="cache.default_expiration">120</property>
    15
  • 16. How to configure ? – cont.
    16
  • 17. How to configure ? – cont.
    Configure caching strategy for each mapping file
    17
  • 18. read only
    If your application needs to read but never modify instances of a persistent class, a read-only cache may be used. This is the simplest and best performing strategy.
    read/write
    If the application needs to update data, a read-write cache might be appropriate. This cache strategy should never be used if serializable transaction isolation level is required.
    nonstrict read/write
    If the application only occasionally needs to update data and strict transaction isolation is not required, a nonstrict-read-write cache might be appropriate.
    Cache StrategieCache Strategies (for Second-Level)
    18
  • 19. 19
    Run Search Function
  • 20. 2009-10-01 16:36:49,250 INFO NHibernate.Cfg.SettingsFactory.CreateCacheProvider(:0) - cache provider: NHibernate.Caches.Prevalence.PrevalenceCacheProvider, NHibernate.Caches.Prevalence
    2009-10-01 16:36:49,250 INFO NHibernate.Cfg.SettingsFactory.BuildSettings(:0) - query cache factory: NHibernate.Cache.StandardQueryCacheFactory
    2009-10-01 16:36:49,578 DEBUG NHibernate.Cache.CacheFactory.CreateCache(:0) - cache for: HelloNHibernate.vo.Contact usage strategy: read-write
    2009-10-01 16:36:49,750 DEBUG NHibernate.Cache.CacheFactory.CreateCache(:0) - cache for: HelloNHibernate.vo.People usage strategy: read-write
    2009-10-01 16:36:50,125 DEBUG NHibernate.Loader.Loader.InitializeEntitiesAndCollections(:0) - total objects hydrated: 3
    2009-10-01 16:36:50,125 DEBUG NHibernate.Engine.TwoPhaseLoad.InitializeEntity(:0) - resolving associations for [HelloNHibernate.vo.People#3]
    2009-10-01 16:36:50,140 DEBUG NHibernate.Engine.Loading.LoadContexts.LocateLoadingCollection(:0) - creating collection wrapper:[HelloNHibernate.vo.People.Contacts#3]
    2009-10-01 16:36:50,140 DEBUG NHibernate.Engine.TwoPhaseLoad.InitializeEntity(:0) - adding entity to second-level cache: [HelloNHibernate.vo.People#3]
    2009-10-01 16:36:50,140 DEBUG NHibernate.Cache.ReadWriteCache.Put(:0) - Caching: HelloNHibernate.vo.People#3
    2009-10-01 16:36:50,140 DEBUG NHibernate.Caches.Prevalence.PrevalenceCache.Get(:0) - Fetching object 'NHibernate-Cache:HelloNHibernate.vo.People:HelloNHibernate.vo.People#3@3' from the cache.
    2009-10-01 16:36:50,156 DEBUG NHibernate.Cache.ReadWriteCache.Put(:0) - Item was already cached: HelloNHibernate.vo.People#3
    20
    Check log
    Set cache provider
    Cache strategy
    Fetch data from cache
  • 21. nHibernate in Action, Manning, 2009/2
    http://www.manning.com/kuate/
    nHibernate online doc: Chapter 14. Improving performance
    https://www.hibernate.org/hib_docs/nhibernate/html/performance.html
    nHibernate online doc: Chapter 20. NHibernate.Caches
    https://www.hibernate.org/hib_docs/nhibernate/html/caches.html
    NHibernate考察系列 06 进阶篇
    http://www.cnblogs.com/riccc/archive/2007/04/17/nhibernate-entity-lifecycle-secondary-cache-interceptor.html
    NHibernate之旅(22):探索NHibernate一级缓存
    http://www.cnblogs.com/lyj/archive/2008/11/24/1340253.html
    21
    Reference

×