Index: VelocityClient.cs
===================================================================
--- VelocityClient.cs (revision 962)
+++ VelocityClient.cs (working copy)
@@ -36,20 +36,21 @@
using System;
using System.Collections.Generic;
-using System.Data.Caching;
+using Microsoft.Data.Caching;
using log4net;
using NHibernate.Cache;
-using CacheException=System.Data.Caching.CacheException;
-using CacheFactory=System.Data.Caching.CacheFactory;
+using CacheException = Microsoft.Data.Caching.DataCacheException;
+using CacheFactory = Microsoft.Data.Caching.DataCacheFactory;
namespace NHibernate.Caches.Velocity
{
public class VelocityClient : ICache
{
- private const string CacheName = "nhibernate";
+ private const string CacheName = "nhibernate2";
private static readonly ILog log;
- private readonly System.Data.Caching.Cache cache;
+ private readonly DataCache cache;
private readonly string region;
+ Dictionary<string, DataCacheLockHandle> locks = new Dictionary<string, DataCacheLockHandle>();
static VelocityClient()
{
@@ -80,13 +81,15 @@
{
return null;
}
- if (log.IsDebugEnabled)
+
+ if (log.IsDebugEnabled)
{
log.DebugFormat("fetching object {0} from the cache", key);
}
- CacheItemVersion version = null;
- return cache.Get(region, key.ToString(), ref version);
+ DataCacheItemVersion version = null;
+ return cache.Get(key.ToString(), out version, region);
+
}
public void Put(object key, object value)
@@ -105,7 +108,7 @@
log.DebugFormat("setting value for item {0}", key);
}
- cache.Put(region, key.ToString(), value, null, null);
+ cache.Put(key.ToString(), value, region);
}
public void Remove(object key)
@@ -137,12 +140,13 @@
public void Lock(object key)
{
- var lockHandle = new LockHandle();
+ DataCacheLockHandle lockHandle;
if (Get(key.ToString()) != null)
{
try
- {
- cache.GetAndLock(region, key.ToString(), TimeSpan.FromMilliseconds(Timeout), out lockHandle);
+ {
+ cache.GetAndLock(key.ToString(), TimeSpan.FromMilliseconds(Timeout), out lockHandle);
+ locks.Add(key.ToString(), lockHandle);
}
catch (CacheException) {}
}
@@ -150,12 +154,17 @@
public void Unlock(object key)
{
- var lockHandle = new LockHandle();
+ DataCacheLockHandle lockHandle ;
if (Get(key.ToString()) != null)
{
try
{
- cache.Unlock(region, key.ToString(), lockHandle);
+ if (locks.ContainsKey(key.ToString()))
+ {
+ cache.Unlock(key.ToString(), locks[key.ToString()], region);
+ locks.Remove(key.ToString());
+ }
+
}
catch (CacheException) {}
}