IBatisNet.DataMapper.Test.NUnit.SqlMapTests.CacheController.TestReturnInstanceOfCachedOject
looks like it tests the readOnly=true, serialize=false case. When I modified
the test to run with readOnly=false, serialize=false the test failed. The last
assert was failing:
Assert.AreNotEqual(firstId, secondId, "hasCode equal");
I haven't dug any deeper into it.
No one has asked for logging messages in the cache controllers. My suggestion
was going to be just decorate the cache controller:
public class DebugLruCacheController : LruCacheController
{
private static readonly ILog log =
LogManager.GetLogger(typeof(LruCacheController));
private LruCacheController lruCacheController = new
LruCacheController();
public new object Remove(object key)
{
if (log.IsDebugEnabled)
{
log.Debug("Removing key [" + key + "] from cache.");
}
return lruCacheController.Remove(key);
}
public new void Flush()
{
if (log.IsDebugEnabled)
{
log.Debug("Flushing cache.");
}
lruCacheController.Flush();
}
// snip
}
but I realized that LruCacheController does interesting things inside its index
accessor (like remove the least recently used item). There's certainly nothing
stopping message similiar to Gentle.Net from being added to the code base. Do
you want specific cache implementation logging (i.e. things relating to how the
LruCacheController is working) or more general statements like "this statement
call with this paramter caused a cache miss"? I don't think our cache keys are
as descriptive as theirs so I don't know how much looking at them in the logs
would help. This is what CacheKey.ToString() looks like:
-585140533|-9223372032920199012
Another solution may be to add events to the CacheStatement to allow users to
monitor things with more context (i.e. pass in the statement name along with
its parameter list). Once your ISqlMapper has been created you could iterate
through its MappedStatement and attach to the CachingStatements events:
// example code that doesn't really exist yet
foreach (CachingStatement cachingStatement in sqlMap.MappedStatements)
{
if (cachingStatement != null)
{
cachingStatement.OnCacheHit += new CacheingStatementHandler(cacheHit);
cachingStatement.OnCacheMiss += new CacheingStatementHandler(cacheMiss);
}
}
Thoughts?
If you're looking at Gentle.Net I'm assuming you've looked at ActiveRecord from
the Castle Project? IBatisNet uses their DynamicProxy library and a number of
users on this list are involved in some way in a few of their projects.
----- Original Message ----
From: Bill Sorensen <[EMAIL PROTECTED]>
To: [email protected]
Sent: Wednesday, December 27, 2006 6:03:49 PM
Subject: RE: Cache not working
I did get the cache to work - sort of. Read/write caches appear to be
broken in v1.5.1.
<cacheModel id="OrderCache" implementation="LRU" readOnly="false"
serialize="true">
causes the following error:
IBatisNet.Common.Exceptions.IBatisNetException: Error caching
serializable object. Cause: Type
'IBatisNet.Common.Utilities.Objects.Members.DelegatePropertySetAccessor'
in Assembly 'IBatisNet.Common, Version=1.4.1.0, Culture=neutral,
PublicKeyToken=ed781d9fc396c6ca' is not marked as serializable.
readOnly="false" serialize="false" - no errors, but did not cache (per
SQL Server Profiler)
readOnly="true" serialize="false" - worked (cached)
Can anyone confirm these issues, or offer suggestions?
As a side note, I turned on logging for the cache:
<logger name="IBatisNet.DataMapper.Configuration.Cache.CacheModel">
<level value="DEBUG" />
</logger>
but nothing was logged by that logger. The closest I found in the logs
was:
DEBUG IBatisNet.DataMapper.Configuration.DomSqlMapBuilder - Registering
trigger statement [OrderMap.Create] to cache model [OrderMap.OrderCache]
I had hoped for something along the lines of Gentle.NET:
Debug: Cache (get) using key: PersistTest_Gentle.Order|select
PT_Order_ID, Order_Notes, PT_Customer_ID from PT_Order where PT_Order_ID
= @PT_Order_ID;|@PT_Order_ID=6400048 (miss)
Is there any way to enable cache logging at this level?
Thanks,
Bill Sorensen
-----Original Message-----
From: Bill Sorensen
Sent: Wednesday, December 27, 2006 11:03 AM
To: [email protected]
Subject: Cache not working
I'm evaluating iBATIS, and have been unable to get the cache to work.
Relevant map sections:
<cacheModels>
<cacheModel id="OrderCache" implementation="LRU"
readOnly="false">
<flushInterval hours="24"/>
<property name="CacheSize" value="1000" />
</cacheModel>
</cacheModels>
<select id="Retrieve" parameterClass="int"
resultMap="OrderResult" cacheModel="OrderCache">
Relevant code section (just test code):
MessageBox.Show("Insure cache is on and turn on
tracing");
ISqlMapper sqlMap = Mapper.Instance();
using (IDalSession session =
sqlMap.OpenConnection())
{
Order ord =
sqlMap.QueryForObject<Order>("OrderMap.Retrieve", 6400048);
Order ord2 =
sqlMap.QueryForObject<Order>("OrderMap.Retrieve", 258474);
MessageBox.Show("About to reload orders
from cache...");
Order ord3 =
sqlMap.QueryForObject<Order>("OrderMap.Retrieve", 6400048);
Order ord4 =
sqlMap.QueryForObject<Order>("OrderMap.Retrieve", 258474);
ord.OrderId = ord.OrderId;
}
MessageBox.Show("Done.");
Using SQL Server Profiler, I can see the two SQL calls for the initial
retrieves. After the "reload" message, I get the same two SQL calls.
Nothing's cached.
I've tried LRU and MEMORY, readOnly false and true, etc. - nothing seems
to make any difference.
Thanks in advance,
Bill Sorensen