![]() |
|
#1
|
|||
|
|||
|
Would someone post an example of their working 2nd level cache configuration? My google fu isn't turning anything up.
Thanks! |
|
#2
|
|||
|
|||
|
Let me rephrase my question. Has anyone successfully used Spring+NHibernate+2nd level cache?
|
|
#3
|
|||
|
|||
|
Yes, I use Spring+NHibernate+2nd level cache successfully.
For other reasons, I manage almost all dinamically in code. This is the piece of code that initializes a Session Factory: Spring.Data.NHibernate.LocalSessionFactoryObject sessionFactory; sessionFactory = new LocalSessionFactoryObject(); // provider sessionFactory.DbProvider = pDbProvider; // custom DelegatingDbProvider object sessionFactory.HibernateProperties.Add("connection .driver_class", pHibernateProvider); // for eg. "NHibernate.Driver.OracleDataClientDriver" sessionFactory.HibernateProperties.Add("dialect", pHibernateDialect); // for eg. "NHibernate.Dialect.Oracle9Dialect" // cache sessionFactory.HibernateProperties.Add("cache.use_ second_level_cache", "true"); sessionFactory.HibernateProperties.Add("cache.regi on_prefix", this.pConfigurationHash); // a string // for Indexus //sessionFactory.HibernateProperties.Add("cache.prov ider_class", "NHibernate.Caches.SharedCache.SharedCacheProvider , NHibernate.Caches.SharedCache"); //sessionFactory.HibernateProperties.Add("cache.serv er", "127.0.0.1:48888"); // for MemCached sessionFactory.HibernateProperties.Add("cache.prov ider_class", "NHibernate.Caches.MemCache.MemCacheProvider, NHibernate.Caches.MemCache"); sessionFactory.HibernateProperties.Add("cache.serv er", "127.0.0.1:11211"); // server address sessionFactory.HibernateProperties.Add("expiration ", "3600"); ... resources for NH mapping sessionFactory.AfterPropertiesSet(); In NH mapping you have to explicitly enable 2nd level caching: <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> <class name="x.y.z, v.w" table="t"> <cache usage="read-write"/> ... properties </class> </hibernate-mapping> And finally, you have to include needed assemblies. For MemCached, for eg. these should be the requirements: Memcached.ClientLibrary.dll NHibernate.Caches.MemCache.dll Commons.dll ICSharpCode.SharpZipLib.dll log4net.dll Cheers |
|
#4
|
|||
|
|||
|
|
|
#5
|
|||
|
|||
|
Any feedback?
I'm interested in other user's experiences with 2nd level cache. egards |
|
#6
|
|||
|
|||
|
We use Spring with NH 1.2 and NCache.
Everything is configured in spring and NH config files. If your app is in a farm be careful what caching concurrency strategy you use with your NH classes. The ReadWrite stategy will require your caching software to support distributed locking. NH flattens the structure of cached classes and still delivers pretty good performance, but if your cache is out of proc, there will be deserialisation overhead each time you hit the cache. This caused us some issues initially ![]() Cheers |
|
#7
|
|||
|
|||
|
Stingray, could you please specify what does "This caused us some issues initially" mean?
Regards |
|
#8
|
|||
|
|||
|
Hi,
Load testing highlighted some issues regarding the deserialisation of objects that were stored in the cache. It significantly impacted the performance of the application because binary deserialisation is cpu intensive. We changed our code to reduce the size of the collection we were retrieving from the cache and the number of times we retrieved. Original code for 1 aspx page execution 40 hits to the cache which retrieved a collection with 500 objects Refactored code for 1 aspx page execution 1 hit to the cache to retrieve a collection with about 50 objects We stored the collection in the HTTPContext, thereby reducing the cache hits to 1 and reduced the collection size by making it page specific. I would do load testing as early as possible in your SDLC. Cheers |
|
#9
|
|||
|
|||
|
Not sure which version of NHibernate.Caches superciccio is using, but in 2.0.0.GA that I'm using you can't specify cache.server as NHibernate parameter. It must be in App.Config like so:
<configuration> <configSections> <section name="memcache" type="NHibernate.Caches.MemCache.MemCacheSectionHa ndler, NHibernate.Caches.MemCache"/> </configSections> <memcache> <memcached host="127.0.0.1" port="11211" /> </memcache> </configuration> |
![]() |
| Thread Tools | |
| Display Modes | |
|
|