[libagilejedi commit] r16 - in trunk: AjileJedi.MemcachedForMonorail.Tests AjileJedi.MemcachedForMonorail/CustomSession...

0 views
Skip to first unread message

codesite...@google.com

unread,
Apr 8, 2008, 6:08:24 PM4/8/08
to libagileje...@googlegroups.com
Author: Daniel.Pupek
Date: Tue Apr 8 13:21:55 2008
New Revision: 16

Modified:
trunk/AjileJedi.MemcachedForMonorail.Tests/MemcachedSessionDictionaryTests.cs
trunk/AjileJedi.MemcachedForMonorail/CustomSessionState/MemCachedSession.cs
trunk/AjileJedi.MemcachedForMonorail/Transcoders/FastSerializerTranscoder.cs

Log:
The clear method now uses the psudo namespace trick and the increment
method of the memcached client....should have better performance.

Keys and Values collections are no longer supported.....these are going
to need some performance tweaks. If I do add them back it will be with
an option to turn them on and off....default will be off.

I may turn them on when DB support is enabled.


Modified: trunk/AjileJedi.MemcachedForMonorail.Tests/MemcachedSessionDictionaryTests.cs
==============================================================================
---
trunk/AjileJedi.MemcachedForMonorail.Tests/MemcachedSessionDictionaryTests.cs (original)
+++
trunk/AjileJedi.MemcachedForMonorail.Tests/MemcachedSessionDictionaryTests.cs
Tue Apr 8 13:21:55 2008
@@ -98,10 +98,10 @@
session.Add("testKey" + i.ToString(), "testValue");
Assert.AreEqual("testValue", session["testKey" + i.ToString()]);
}
- Assert.AreEqual(100, session.Count, "the session value count is wrong.");
-
+ //Assert.AreEqual(100, session.Count, "the session value count is wrong.");
+
session.Clear();
- Assert.AreEqual(0, session.Count, "the session value count is wrong.");
+ //Assert.AreEqual(0, session.Count, "the session value count is wrong.");
for (int i = 0; i < 100; i++)
{
Assert.IsNull(session["testKey" + i.ToString()]);

Modified: trunk/AjileJedi.MemcachedForMonorail/CustomSessionState/MemCachedSession.cs
==============================================================================
---
trunk/AjileJedi.MemcachedForMonorail/CustomSessionState/MemCachedSession.cs (original)
+++
trunk/AjileJedi.MemcachedForMonorail/CustomSessionState/MemCachedSession.cs
Tue Apr 8 13:21:55 2008
@@ -49,7 +49,7 @@
{
_sessionId = sessionId;
_mcClient = new Enyim.Caching.MemcachedClient(configSection);
-
+ this._SessionTimeToLiveMinutes = 20;

}

@@ -75,25 +75,17 @@
{
get {

- List<string> keysList = _mcClient.Get<List<string>>(_sessionId + ":sessionkeys");
- if (keysList == null)
- {
- keysList = new List<string>();
- UpdateKeys(keysList);
- }
- return keysList;
+// List<string> keysList = _mcClient.Get<List<string>>(_sessionId + ":sessionkeys");
+// if (keysList == null)
+// {
+// keysList = new List<string>();
+// UpdateKeys(keysList);
+// }
+// return keysList;
+ throw new NotSupportedException("Support for the Keys collection
may be added later...at this time it is too costly to track keys.");
}
}
- /// <summary>
- /// Replaces the List of keys stored on
- /// the memcached servers
- /// </summary>
- /// <param name="keys"></param>
- private void UpdateKeys(List<string> keys)
- {
- _mcClient.Store(StoreMode.Set,_sessionId + ":sessionkeys", keys);
-
- }
+

public bool Remove(string key)
{
@@ -165,13 +157,7 @@

public void Clear()
{
- IList<string> keys = (IList<string>)this.Keys;
- foreach (string key in keys)
- {
- this.Remove(key);
- }
- this.UpdateKeys(null);
-
+ this.IncrementRevision();
}

public bool Contains(KeyValuePair<string, object> item)
@@ -186,7 +172,7 @@

public int Count
{
- get { return this.Keys.Count; }
+ get { throw new NotSupportedException("The method or operation is
not implemented."); }
}

public bool IsReadOnly
@@ -229,48 +215,66 @@

#endregion

+ #region Properties
+
+ private double _SessionTimeToLiveMinutes;
+ public double SessionTimeToLiveMinutes
+ {
+ get { return _SessionTimeToLiveMinutes; }
+ set { _SessionTimeToLiveMinutes = value; }
+ }
+ #endregion
+
#region Private Members

private string GetMemCachedKey(string sessionKey)
{
- return _sessionId + ":sessionkey:" + sessionKey;
+ return string.Format("session.{0}.rev.{1}.{2}", _sessionId,
GetRevision(), sessionKey);
}

- private object GetMemCachedValue(string key)
+ public int GetRevision()
{
- return _mcClient.Get(GetMemCachedKey(key));
+ return _mcClient.Get<int>(this.RevisionKey);

}

- private void WriteMemCachedValue(string key, object value)
+ private void IncrementRevision()
{
- _mcClient.Store(StoreMode.Set, GetMemCachedKey(key), value);
+ _mcClient.Store(StoreMode.Add, this.RevisionKey, 1,
TimeSpan.FromMinutes(this.SessionTimeToLiveMinutes + 15));
+ long newRevision = _mcClient.Increment(this.RevisionKey, 1);
+ _logger.InfoFormat("New Revision {0} for session {1}",
newRevision.ToString(), _sessionId);

- ICollection<string> keys = this.Keys;
+ }

- if (!keys.Contains(key))
- {
- // Add the new key to the key list
- keys.Add(key);
- this.UpdateKeys((List<string>)keys);
- }
+ /// <summary>
+ /// Used inernally to get the key that the current revision
+ /// number is stored under
+ /// </summary>
+ public string RevisionKey
+ {
+ get { return String.Format("session.{0}.rev", _sessionId); }
+
+ }
+ private object GetMemCachedValue(string key)
+ {
+ return _mcClient.Get(GetMemCachedKey(key));

+ }

+ private void WriteMemCachedValue(string key, object value)
+ {
+ _mcClient.Store(StoreMode.Set, GetMemCachedKey(key), value, GetTimeToLive());

}

private void RemoveMemCachedValue(string key)
{
_mcClient.Remove(GetMemCachedKey(key));
-
- ICollection<string> keys = this.Keys;
-
- if (keys.Contains(key))
- {
- // Add the new key to the key list
- keys.Remove(key);
- this.UpdateKeys((List<string>)keys);
- }
+
+ }
+ private TimeSpan GetTimeToLive()
+ {
+ return TimeSpan.FromMinutes(this.SessionTimeToLiveMinutes);
}
#endregion

Modified: trunk/AjileJedi.MemcachedForMonorail/Transcoders/FastSerializerTranscoder.cs
==============================================================================
---
trunk/AjileJedi.MemcachedForMonorail/Transcoders/FastSerializerTranscoder.cs (original)
+++
trunk/AjileJedi.MemcachedForMonorail/Transcoders/FastSerializerTranscoder.cs
Tue Apr 8 13:21:55 2008
@@ -26,7 +26,7 @@
writer.WriteObject(o);

cacheitem.Data = new ArraySegment<byte>(writer.ToArray());
-
+
return cacheitem;

}

Reply all
Reply to author
Forward
0 new messages