You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by Sara O'Neal <sa...@cadre5.com> on 2007/02/15 01:50:42 UTC
Question about Caching in iBatis .NET
I am new to iBatis, and have been playing around with the caching
feature. I'm not sure if I am doing something wrong, or if it is
working incorrectly. I am trying to use the FIFO caching model in
iBatis .NET, DataMapper 1.5.1, using SQL Server 2005. Here is my model:
<cacheModels>
<cacheModel id="addressCacheF" implementation="FIFO">
<flushInterval hours="24" />
<flushOnExecute statement="InsertAddress" />
<flushOnExecute statement="UpdateAddress" />
<property name="CacheSize" value="5" />
</cachModel>
</cacheModels>
I also have caching enabled:
<settings>
<setting useStatementNamespaces="true" />
<setting cacheModelsEnabled="true" />
<setting validateSqlMap="true" />
</settings>
Please excuse any errors, because I retyped this. So, from what I
understand, this is using a First in First Out algorithm for caching and
it caches a Maximum of 5 items. However, when I apply this cache model
to the code that I wrote, it doesn't seem to work correctly. I am using
SQL Server Profiler to trace any database events (I also enabled logging
for iBatis to track cache hits/misses). The data I am retrieving is
from a table of clients, and I am retrieving the client by a client id.
The sequence I am using is:
1, 2, 3, 4, 5
For this sequence there are 5 cache misses and all 5 should now be in
the cache. Next, I use the same sequence and get 5 cache hits. Both
the log and the profiler back this up.
Then, I enter 6 and get a cache miss. This means 2 things. First, 6 is
going to be added to the cache. Second, since the cache is full, it
uses FIFO to replace the first item in the cache, which was 1. So, I
can now enter this sequence:
2, 3, 4, 5, 6
Sure enough, I get 5 cache hits. Next, I want to go back to 1. When I
enter that value, I should get a miss, and indeed do. It should also
add the object to the cache, mean I should have: 3, 4, 5, 6, 1 in my
cache. BUT, it doesn't, I still have 2, 3, 4, 5, 6 in my cache. More
than that, though, when I try 7, it gets added to the cache, but none of
the other objects get replaced! I can add 8, 9, 10, 11...getting misses
on each the first time. However, I can then go back and try 2, 3, 4, 5,
6, 7, 8, 9, 10, 11 and get hits on every single one of them. Finally, I
try 1 again and get a miss...I continue trying and continue getting a
miss.
So, is there something I missing about the caching, or is there
something I not understanding about the cache size, or what?
I have tried using the other cache implementations as well. I'm not
sure what the MEMORY is supposed to do...so I can't really tell if it is
working correctly or not. The LRU, however, doesn't seem to work
correctly either, but that is a completely different story. Please
advise if I should report this as a bug, or if I do not understand the
way it SHOULD work.
thanks,
Sara O'Neal
Software Developer, Cadre5, LLC
sara.oneal@cadre5.com <ma...@cadre5.com>
RE: Question about Caching in iBatis .NET
Posted by Sara O'Neal <sa...@cadre5.com>.
So no one can help me with this problem or tell me if it is a bug?
thanks,
Sara
________________________________
From: Sara O'Neal
Sent: Wednesday, February 14, 2007 7:51 PM
To: user-cs@ibatis.apache.org
Subject: Question about Caching in iBatis .NET
I am new to iBatis, and have been playing around with the caching
feature. I'm not sure if I am doing something wrong, or if it is
working incorrectly. I am trying to use the FIFO caching model in
iBatis .NET, DataMapper 1.5.1, using SQL Server 2005. Here is my model:
<cacheModels>
<cacheModel id="addressCacheF" implementation="FIFO">
<flushInterval hours="24" />
<flushOnExecute statement="InsertAddress" />
<flushOnExecute statement="UpdateAddress" />
<property name="CacheSize" value="5" />
</cachModel>
</cacheModels>
I also have caching enabled:
<settings>
<setting useStatementNamespaces="true" />
<setting cacheModelsEnabled="true" />
<setting validateSqlMap="true" />
</settings>
Please excuse any errors, because I retyped this. So, from what I
understand, this is using a First in First Out algorithm for caching and
it caches a Maximum of 5 items. However, when I apply this cache model
to the code that I wrote, it doesn't seem to work correctly. I am using
SQL Server Profiler to trace any database events (I also enabled logging
for iBatis to track cache hits/misses). The data I am retrieving is
from a table of clients, and I am retrieving the client by a client id.
The sequence I am using is:
1, 2, 3, 4, 5
For this sequence there are 5 cache misses and all 5 should now be in
the cache. Next, I use the same sequence and get 5 cache hits. Both
the log and the profiler back this up.
Then, I enter 6 and get a cache miss. This means 2 things. First, 6 is
going to be added to the cache. Second, since the cache is full, it
uses FIFO to replace the first item in the cache, which was 1. So, I
can now enter this sequence:
2, 3, 4, 5, 6
Sure enough, I get 5 cache hits. Next, I want to go back to 1. When I
enter that value, I should get a miss, and indeed do. It should also
add the object to the cache, mean I should have: 3, 4, 5, 6, 1 in my
cache. BUT, it doesn't, I still have 2, 3, 4, 5, 6 in my cache. More
than that, though, when I try 7, it gets added to the cache, but none of
the other objects get replaced! I can add 8, 9, 10, 11...getting misses
on each the first time. However, I can then go back and try 2, 3, 4, 5,
6, 7, 8, 9, 10, 11 and get hits on every single one of them. Finally, I
try 1 again and get a miss...I continue trying and continue getting a
miss.
So, is there something I missing about the caching, or is there
something I not understanding about the cache size, or what?
I have tried using the other cache implementations as well. I'm not
sure what the MEMORY is supposed to do...so I can't really tell if it is
working correctly or not. The LRU, however, doesn't seem to work
correctly either, but that is a completely different story. Please
advise if I should report this as a bug, or if I do not understand the
way it SHOULD work.
thanks,
Sara O'Neal
Software Developer, Cadre5, LLC
sara.oneal@cadre5.com <ma...@cadre5.com>