public void CanSetAndGetAnEntry() { var mCache = new DefaultMemCached(10); mCache.Set("X", "Y"); Assert.AreEqual("Y", mCache.Get("X")); Assert.IsNull(mCache.Get("Y")); }
public void CanSetAnExistingEntry() { var mCache = new DefaultMemCached(10); mCache.Set("X", "Y"); mCache.Set("X", "Z"); Assert.AreEqual("Z", mCache.Get("X")); }
public void CanDeleteAnEntry() { var mCache = new DefaultMemCached(10); mCache.Set("X", "Y"); Assert.IsNotNull(mCache.Get("X")); mCache.Delete("X"); Assert.IsNull(mCache.Get("X")); }
public void OldestMessagesAreEvicted() { const int size = 5; var mCache = new DefaultMemCached(size); for (var i = 1; i <= size + 2; ++i) { mCache.Set("K" + i, i.ToString()); } Assert.IsNull(mCache.Get("K1")); Assert.IsNull(mCache.Get("K2")); Assert.IsNotNull(mCache.Get("K3")); }
/** * TODO: * * - Introduce Unity and use Dependency Injection * - Stress tests * - Manage exceptions * - Preallocate all the needed memoory at the startup (if possible) * - Implement different versions and compare their performances * */ static void Main(string[] args) { IMemCached memCached = new DefaultMemCached(10); memCached.Set("A", "Apple"); memCached.Set("B", "Bubble"); memCached.Set("C", "Cat"); memCached.Set("B", "Many Bubbles"); memCached.Set("C", "A lot of Cats"); System.Console.WriteLine("'B' is " + memCached.Get("B")); System.Console.WriteLine("'C' is " + memCached.Get("C")); }
public void GettingAKeyChangesItsPriority() { const int size = 5; var mCache = new DefaultMemCached(size); for (var i = 1; i <= size; ++i) { mCache.Set("K" + i, i.ToString()); } mCache.Get("K1"); mCache.Set("K6", "6"); mCache.Set("K7", "7"); Assert.IsNotNull(mCache.Get("K1")); Assert.IsNull(mCache.Get("K2")); Assert.IsNull(mCache.Get("K3")); Assert.IsNotNull(mCache.Get("K4")); }
public void CanCreateAMemCachedInstance() { var mCache = new DefaultMemCached(10); Assert.IsNotNull(mCache); }