public void PurgeLuaScriptCache() { const string Script = "redis.call('set', @PurgeLuaScriptCacheKey, @PurgeLuaScriptCacheValue)"; var first = LuaScript.Prepare(Script); var fromCache = LuaScript.Prepare(Script); Assert.IsTrue(object.ReferenceEquals(first, fromCache)); LuaScript.PurgeCache(); var shouldBeNew = LuaScript.Prepare(Script); Assert.IsFalse(object.ReferenceEquals(first, shouldBeNew)); }
public void PurgeLuaScriptOnFinalize() { const string Script = "redis.call('set', @PurgeLuaScriptOnFinalizeKey, @PurgeLuaScriptOnFinalizeValue)"; LuaScript.PurgeCache(); Assert.Equal(0, LuaScript.GetCachedScriptCount()); // This has to be a separate method to guarantee that the created LuaScript objects go out of scope, // and are thus available to be GC'd PurgeLuaScriptOnFinalizeImpl(Script); CollectGarbage(); Assert.Equal(0, LuaScript.GetCachedScriptCount()); LuaScript.Prepare(Script); Assert.Equal(1, LuaScript.GetCachedScriptCount()); }
public void PurgeLuaScriptOnFinalize() { const string Script = "redis.call('set', @PurgeLuaScriptOnFinalizeKey, @PurgeLuaScriptOnFinalizeValue)"; LuaScript.PurgeCache(); Assert.AreEqual(0, LuaScript.GetCachedScriptCount()); // This has to be a separate method to guarantee that the created LuaScript objects go out of scope, // and are thus available to be GC'd _PurgeLuaScriptOnFinalize(Script); GC.Collect(2, GCCollectionMode.Forced, blocking: true); GC.WaitForPendingFinalizers(); Assert.AreEqual(0, LuaScript.GetCachedScriptCount()); var shouldBeNew = LuaScript.Prepare(Script); Assert.AreEqual(1, LuaScript.GetCachedScriptCount()); }