Skip to content

Commit

Permalink
Replace SysCache with HashtableCache
Browse files Browse the repository at this point in the history
It looks like SysCache has a bug with EvictEntity, the the commit
94402f3 appeared because cache provided
by SysCache didn't clear properly, it worked when I replaced the
EvictEntity(typeof(Blog).FullName) with
EvictEntity(typeof(Blog).FullName, 2), the logs reported that they
evicted all Blogs, but immediately later  hit the cache.
  • Loading branch information
jahav committed Sep 2, 2014
1 parent 94402f3 commit 912d54b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
16 changes: 12 additions & 4 deletions Nerula.Test/Cache2ndLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using NHibernate.Linq;
using NHibernate.Cfg;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NHibernate.Caches.SysCache;
using Nerula.Data;
using System.Collections.Generic;
using log4net;
Expand Down Expand Up @@ -30,14 +29,20 @@ public void Init2ndLvlCache()
cfg
.SetProperty(Environment.UseSecondLevelCache, "true")
.SetProperty(Environment.CacheDefaultExpiration, "10") // Default 2nd lvl cache expiration, in seconds
.SetProperty(Environment.CacheProvider, typeof(SysCacheProvider).AssemblyQualifiedName)
.SetProperty(Environment.CacheProvider, typeof(NHibernate.Cache.HashtableCacheProvider).AssemblyQualifiedName)
.AddAssembly(typeof(Blog).Assembly)
.SetCacheConcurrencyStrategy(typeof(Blog).FullName, "read-write")
.SetCacheConcurrencyStrategy(typeof(Post).FullName, "read-write")
.SetCacheConcurrencyStrategy(typeof(Project).FullName, "read-write");
});
}

[TestCleanup]
public void TestCleanup()
{
DatabaseTearDown();
}

/// <summary>
/// When I query without a synchronize tag, I evict all entites that are in the cache.
/// </summary>
Expand Down Expand Up @@ -141,10 +146,10 @@ public void Full2ndLvlCacheMiss()
{
CreateData();

SessionFactory.EvictEntity(typeof(Blog).FullName);

log4net.Config.BasicConfigurator.Configure(memoryAppender);

SessionFactory.EvictEntity(typeof(Blog).FullName);

using (var session = SessionFactory.OpenSession())
{
using (var tx = session.BeginTransaction())
Expand All @@ -163,6 +168,9 @@ public void Full2ndLvlCacheMiss()
"Cached: Nerula.Data.Blog#2"
};

foreach (var e in memoryAppender.GetEvents())
System.Console.WriteLine("{0}: {1}",e.LoggerName, e.RenderedMessage);

CollectionAssert.AreEqual(expectedEvents, cacheEvents);
}

Expand Down
1 change: 0 additions & 1 deletion Nerula.Test/DatabaseTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Nerula.Data;
using NHibernate;
using NHibernate.Caches.SysCache;
using NHibernate.Cfg;
using NHibernate.Dialect;
using NHibernate.Driver;
Expand Down
3 changes: 0 additions & 3 deletions Nerula.Test/Nerula.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@
<Reference Include="NHibernate">
<HintPath>..\packages\NHibernate.3.3.3.4001\lib\Net35\NHibernate.dll</HintPath>
</Reference>
<Reference Include="NHibernate.Caches.SysCache">
<HintPath>..\packages\NHibernate.Caches.SysCache.3.3.3.4000\lib\net35\NHibernate.Caches.SysCache.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Data.SQLite">
Expand Down
1 change: 0 additions & 1 deletion Nerula.Test/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<package id="Iesi.Collections" version="3.2.0.4000" targetFramework="net45" />
<package id="log4net" version="2.0.3" targetFramework="net45" />
<package id="NHibernate" version="3.3.3.4001" targetFramework="net45" />
<package id="NHibernate.Caches.SysCache" version="3.3.3.4000" targetFramework="net45" />
<package id="NHibernate.SetForNet4" version="1.0.3" targetFramework="net45" />
<package id="System.Data.SQLite.Core" version="1.0.93.0" targetFramework="net45" />
</packages>

0 comments on commit 912d54b

Please sign in to comment.