Skip to content

Commit 42d2cc1

Browse files
Added support for LRUMap with a size of zero.
Signed-off-by: Eamon Hetherton <[email protected]>
1 parent 8b5ae02 commit 42d2cc1

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/NHibernate.Test/UtilityTest/LRUMapFixture.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ public void GetEntrySet()
8080
{
8181
Assert.AreNotEqual(-1, entry.Value.ToString().IndexOf("data:"));
8282
}
83-
}
83+
}
84+
85+
[Test]
86+
public void PutWithSizeLimitOfZero()
87+
{
88+
IDictionary cache = new LRUMap(0);
89+
90+
cache.Add("key", "data");
91+
92+
string data = (string)cache["key"];
93+
Assert.IsNull(data, "Data is wrong.");
94+
}
8495
}
8596
}

src/NHibernate/Util/LRUMap.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public override object this[object key]
5656

5757
public override void Add(object key, object value)
5858
{
59+
if (maximumSize == 0)
60+
{
61+
return;
62+
}
5963
int mapSize = Count;
6064
if (mapSize >= maximumSize)
6165
{
@@ -74,6 +78,10 @@ public override void Add(object key, object value)
7478
private void RemoveLRU()
7579
{
7680
object key = FirstKey;
81+
if (ReferenceEquals(null, key))
82+
{
83+
return;
84+
}
7785
// be sure to call super.get(key), or you're likely to
7886
// get infinite promotion recursion
7987
object value = base[key];

0 commit comments

Comments
 (0)