Skip to content

Added support for LRUMap with a size of zero. #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/NHibernate.Test/UtilityTest/LRUMapFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ public void GetEntrySet()
{
Assert.AreNotEqual(-1, entry.Value.ToString().IndexOf("data:"));
}
}
}

[Test]
public void PutWithSizeLimitOfZero()
{
IDictionary cache = new LRUMap(0);

cache.Add("key", "data");

string data = (string)cache["key"];
Assert.IsNull(data, "Data is wrong.");
}
}
}
8 changes: 8 additions & 0 deletions src/NHibernate/Util/LRUMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public override object this[object key]

public override void Add(object key, object value)
{
if (maximumSize == 0)
{
return;
}
int mapSize = Count;
if (mapSize >= maximumSize)
{
Expand All @@ -74,6 +78,10 @@ public override void Add(object key, object value)
private void RemoveLRU()
{
object key = FirstKey;
if (ReferenceEquals(null, key))
{
return;
}
// be sure to call super.get(key), or you're likely to
// get infinite promotion recursion
object value = base[key];
Expand Down