public PatreonRewardsService(IBotCredentials creds, DbService db, CurrencyService currency, DiscordSocketClient client, IDataCache cache) { _log = LogManager.GetCurrentClassLogger(); _creds = creds; _db = db; _currency = currency; _cache = cache; _key = _creds.RedisKey() + "_patreon_rewards"; _pledges = new FactoryCache <PatreonUserAndReward[]>(() => { var r = _cache.Redis.GetDatabase(); var data = r.StringGet(_key); if (data.IsNullOrEmpty) { return(null); } else { return(JsonConvert.DeserializeObject <PatreonUserAndReward[]>(data)); } }, TimeSpan.FromSeconds(20)); if (client.ShardId == 0) { Updater = new Timer(async _ => await RefreshPledges(), null, TimeSpan.Zero, Interval); } }
public virtual async Task <Endpoint?> HostEndpointAsync(Type Key) { var ret = default(Endpoint); if (!FactoryCache.ContainsKey(Key)) { var ChildOptions = new Endpoint( Options.Provider, Options.Host, Options.Port, Guid.NewGuid().ToString() ); var Handler = Activator.CreateInstance(Key); if (Handler is { } V1) { var NewProvider = new IpcServer(ChildOptions, V1); var HostingLocation = await NewProvider.StartHostingAsync() .DefaultAwait() ; FactoryCache[Key] = NewProvider; EndpointCache[Key] = HostingLocation; ret = HostingLocation; } } else { ret = EndpointCache[Key]; } return(ret); }
/// <summary> /// Returns the activation factory without using the cache. Avoiding cache behavior is important /// for app that use this API because they need to deal with crashing broker scenarios where cached /// factories would be stale (pointing to a bad proxy) /// </summary> public static IActivationFactory GetActivationFactory(Type type) { if (type == null) { throw new ArgumentNullException(nameof(type)); } __ComObject factory = FactoryCache.Get().GetActivationFactory( type.FullName, InternalTypes.IUnknown, skipCache: true); return((IActivationFactory)factory); }
/// <summary> /// Clears the cache. /// </summary> public void ClearCaches() { FactoryCache.Clear(); ParameterizedFactoryCache.Clear(); }