Advertisement
Guest User

Rene

a guest
Jul 22nd, 2009
698
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. Index: VelocityClient.cs
  2. ===================================================================
  3. --- VelocityClient.cs (revision 962)
  4. +++ VelocityClient.cs (working copy)
  5. @@ -36,20 +36,21 @@
  6.  
  7. using System;
  8. using System.Collections.Generic;
  9. -using System.Data.Caching;
  10. +using Microsoft.Data.Caching;
  11. using log4net;
  12. using NHibernate.Cache;
  13. -using CacheException=System.Data.Caching.CacheException;
  14. -using CacheFactory=System.Data.Caching.CacheFactory;
  15. +using CacheException = Microsoft.Data.Caching.DataCacheException;
  16. +using CacheFactory = Microsoft.Data.Caching.DataCacheFactory;
  17.  
  18. namespace NHibernate.Caches.Velocity
  19. {
  20. public class VelocityClient : ICache
  21. {
  22. - private const string CacheName = "nhibernate";
  23. + private const string CacheName = "nhibernate2";
  24. private static readonly ILog log;
  25. - private readonly System.Data.Caching.Cache cache;
  26. + private readonly DataCache cache;
  27. private readonly string region;
  28. + Dictionary<string, DataCacheLockHandle> locks = new Dictionary<string, DataCacheLockHandle>();
  29.  
  30. static VelocityClient()
  31. {
  32. @@ -80,13 +81,15 @@
  33. {
  34. return null;
  35. }
  36. - if (log.IsDebugEnabled)
  37. +
  38. + if (log.IsDebugEnabled)
  39. {
  40. log.DebugFormat("fetching object {0} from the cache", key);
  41. }
  42.  
  43. - CacheItemVersion version = null;
  44. - return cache.Get(region, key.ToString(), ref version);
  45. + DataCacheItemVersion version = null;
  46. + return cache.Get(key.ToString(), out version, region);
  47. +
  48. }
  49.  
  50. public void Put(object key, object value)
  51. @@ -105,7 +108,7 @@
  52. log.DebugFormat("setting value for item {0}", key);
  53. }
  54.  
  55. - cache.Put(region, key.ToString(), value, null, null);
  56. + cache.Put(key.ToString(), value, region);
  57. }
  58.  
  59. public void Remove(object key)
  60. @@ -137,12 +140,13 @@
  61.  
  62. public void Lock(object key)
  63. {
  64. - var lockHandle = new LockHandle();
  65. + DataCacheLockHandle lockHandle;
  66. if (Get(key.ToString()) != null)
  67. {
  68. try
  69. - {
  70. - cache.GetAndLock(region, key.ToString(), TimeSpan.FromMilliseconds(Timeout), out lockHandle);
  71. + {
  72. + cache.GetAndLock(key.ToString(), TimeSpan.FromMilliseconds(Timeout), out lockHandle);
  73. + locks.Add(key.ToString(), lockHandle);
  74. }
  75. catch (CacheException) {}
  76. }
  77. @@ -150,12 +154,17 @@
  78.  
  79. public void Unlock(object key)
  80. {
  81. - var lockHandle = new LockHandle();
  82. + DataCacheLockHandle lockHandle ;
  83. if (Get(key.ToString()) != null)
  84. {
  85. try
  86. {
  87. - cache.Unlock(region, key.ToString(), lockHandle);
  88. + if (locks.ContainsKey(key.ToString()))
  89. + {
  90. + cache.Unlock(key.ToString(), locks[key.ToString()], region);
  91. + locks.Remove(key.ToString());
  92. + }
  93. +
  94. }
  95. catch (CacheException) {}
  96. }
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement