public CachedAllAccount(string name, IDictionary <string, string> options, ICachableAccount account) : base(name, options) { if (!(account is ICachableAccountAll) && !(account is ICachableAccountInc)) { throw new ArgumentException("can't cache account class that " + "doesn't implement IAccountAll or IAccountInc interface"); } Account = account; refresh_inc = -1; if (options.ContainsKey("refresh_inc")) { refresh_inc = int.Parse(options["refresh_inc"]); } else if (Account is ICachableAccountInc) { refresh_inc = 300; } refresh_full = -1; if (options.ContainsKey("refresh_full")) { refresh_full = int.Parse(options["refresh_full"]); } else if (Account is ICachableAccountAll) { refresh_full = 3600; } // initialize cached data try { RefreshFull(); } catch (Exception ex) { Log.Error("ADAccount[" + Name + "] unable to fill cache: " + ex.Message); } // create timers to periodically update cached data if (refresh_inc > 0 && refresh_inc != refresh_full) // && Account is IAccountInc) { refresh_inc_timer = new Timer(refresh_inc); refresh_inc_timer.Elapsed += RefreshIncElapsed; refresh_inc_timer.Enabled = true; } if (refresh_full > 0) // && Account is IAccountAll) { refresh_full_timer = new Timer(refresh_full); refresh_full_timer.Elapsed += RefreshFullElapsed; refresh_full_timer.Enabled = true; } }
public CachedAccount(string name, IDictionary <string, string> options, ICachableAccount account) : base(name, options) { Account = account; int cache_positive_time = 600; if (options.ContainsKey("cache_positive_time")) { cache_positive_time = int.Parse(options["cache_positive_time"]); } int cache_negative_time = 60; if (options.ContainsKey("cache_negative_time")) { cache_negative_time = int.Parse(options["cache_negative_time"]); } int cache_positive_max_size = 10000; if (options.ContainsKey("cache_positive_max_size")) { cache_positive_time = int.Parse(options["cache_positive_max_size"]); } int cache_negative_max_size = 1000; if (options.ContainsKey("cache_negative_max_size")) { cache_negative_time = int.Parse(options["cache_negative_max_size"]); } cache_positive = null; cache_negative = null; if (cache_positive_time > 0) { cache_positive = new ExpirableCache(cache_positive_time, cache_positive_max_size); } if (cache_negative_time > 0) { cache_negative = new ExpirableCache(cache_negative_time, cache_negative_max_size); } //cache = new MemoryCache("CachedAccount[" + name + "]"); //cache = new Dictionary<string, Tuple<AccountStatus, DateTime, TimeSpan, int>>(); }
public CachedAllAccount(string name, IDictionary<string, string> options, ICachableAccount account) : base(name, options) { if (!(account is ICachableAccountAll) && !(account is ICachableAccountInc)) { throw new ArgumentException("can't cache account class that " + "doesn't implement IAccountAll or IAccountInc interface"); } Account = account; refresh_inc = -1; if (options.ContainsKey("refresh_inc")) { refresh_inc = int.Parse(options["refresh_inc"]); } else if (Account is ICachableAccountInc) { refresh_inc = 300; } refresh_full = -1; if (options.ContainsKey("refresh_full")) { refresh_full = int.Parse(options["refresh_full"]); } else if (Account is ICachableAccountAll) { refresh_full = 3600; } // initialize cached data try { RefreshFull(); } catch (Exception ex) { Log.Error("ADAccount[" + Name + "] unable to fill cache: " + ex.Message); } // create timers to periodically update cached data if (refresh_inc > 0 && refresh_inc != refresh_full) // && Account is IAccountInc) { refresh_inc_timer = new Timer(refresh_inc); refresh_inc_timer.Elapsed += RefreshIncElapsed; refresh_inc_timer.Enabled = true; } if (refresh_full > 0) // && Account is IAccountAll) { refresh_full_timer = new Timer(refresh_full); refresh_full_timer.Elapsed += RefreshFullElapsed; refresh_full_timer.Enabled = true; } }
public CachedAccount(string name, IDictionary<string, string> options, ICachableAccount account) : base(name, options) { Account = account; int cache_positive_time = 600; if (options.ContainsKey("cache_positive_time")) { cache_positive_time = int.Parse(options["cache_positive_time"]); } int cache_negative_time = 60; if (options.ContainsKey("cache_negative_time")) { cache_negative_time = int.Parse(options["cache_negative_time"]); } int cache_positive_max_size = 10000; if (options.ContainsKey("cache_positive_max_size")) { cache_positive_time = int.Parse(options["cache_positive_max_size"]); } int cache_negative_max_size = 1000; if (options.ContainsKey("cache_negative_max_size")) { cache_negative_time = int.Parse(options["cache_negative_max_size"]); } cache_positive = null; cache_negative = null; if (cache_positive_time > 0) { cache_positive = new ExpirableCache(cache_positive_time, cache_positive_max_size); } if (cache_negative_time > 0) { cache_negative = new ExpirableCache(cache_negative_time, cache_negative_max_size); } //cache = new MemoryCache("CachedAccount[" + name + "]"); //cache = new Dictionary<string, Tuple<AccountStatus, DateTime, TimeSpan, int>>(); }