/// <summary> /// Initialize a phoenix with provided cacheDuration and staleWhileRevalidate values /// </summary> /// <param name="invocation"></param> /// <param name="info"></param> public Phoenix(_IInvocation invocation, CacheItem info) { _info = info.CloneWithoutData(); _phoenixState = _info.StaleWhileRevalidate > 0 ? (IPhoenixState) new InActivePhoenix() : new DisposingPhoenix(DieAsync()); if (invocation.Proxy != null) { // It is really a dynamic proxy _instanceTargetField = invocation.Proxy.GetType().GetField("__target", BindingFlags.Public | BindingFlags.Instance); } Arguments = invocation.Arguments; MethodInfo = invocation.Method; _timer = new Timer(_ => Reborn(), null, _info.GetRefreshTime(), TimeSpan.Zero); }
protected virtual CacheItem GetCacheItem(object invocationBareResult) { if (invocationBareResult == null) { return(null); } var newCacheItem = _info.CloneWithoutData(); newCacheItem.CreatedTime = DateTime.UtcNow; newCacheItem.Data = invocationBareResult; return(newCacheItem); }
/// <summary> /// Initialize a phoenix with provided cacheDuration and staleWhileRevalidate values /// </summary> /// <param name="invocation"></param> /// <param name="info"></param> public Phoenix(_IInvocation invocation, CacheItem info) { _id = Guid.NewGuid().ToString("N"); _info = info.CloneWithoutData(); _phoenixState = _info.StaleWhileRevalidate > 0 ? (IPhoenixState) new InActivePhoenix() : new DisposingPhoenix(DieAsync()); if (invocation.Proxy != null) { // It is really a dynamic proxy _instanceTargetField = invocation.Proxy.GetType().GetField("__target", BindingFlags.Public | BindingFlags.Instance); } Arguments = invocation.Arguments; MethodInfo = invocation.Method; _allPhoenix[_id] = this; //NOTE: Memory leak: http://www.codeproject.com/Questions/185734/Threading-Timer-prevents-GC-collection _timer = new Timer(RebornCallback, _id, _info.GetRefreshTime(), TimeSpan.Zero); }
/// <summary> /// Initialize a phoenix with provided cacheDuration and staleWhileRevalidate values /// </summary> /// <param name="invocation"></param> /// <param name="info"></param> public Phoenix(_IInvocation invocation, CacheItem info) { _id = Guid.NewGuid().ToString("N"); _info = info.CloneWithoutData(); _phoenixState = _info.StaleWhileRevalidate > 0 ? (IPhoenixState) new InActivePhoenix() : new DisposingPhoenix(DieAsync()); if (invocation.Proxy != null) { // It is really a dynamic proxy _instanceTargetField = invocation.Proxy.GetType().GetField("__target", BindingFlags.Public | BindingFlags.Instance); } Arguments = invocation.Arguments; MethodInfo = invocation.Method; _allPhoenix[_id] = this; //NOTE: Memory leak: http://www.codeproject.com/Questions/185734/Threading-Timer-prevents-GC-collection _timer = new Timer(RebornCallback, _id, _info.GetRefreshTime(), TimeSpan.Zero); }