/// <summary> /// Initializes a new instance of the <see cref="WarmupCacheJob" /> class. /// </summary> /// <param name="context">The context.</param> /// <param name="settings">The settings.</param> public WarmupCacheJob(CrmDbContext context, WarmupCacheSettings settings) { this.Context = context; this.Settings = settings; this.AppDataFullPath = settings.AppDataPath.StartsWith("~/") ? HostingEnvironment.MapPath(settings.AppDataPath) : settings.AppDataPath; }
/// <summary> /// Initializes a new instance of the <see cref="PersistCachedRequestsJob" /> class. /// </summary> /// <param name="objectCache">Reference to the ObjectCache.</param> /// <param name="settings">The settings.</param> public PersistCachedRequestsJob(ObjectCache objectCache, WarmupCacheSettings settings) { this.Settings = settings; this.ObjectCache = objectCache; this.AppDataFullPath = settings.AppDataPath.StartsWith("~/") ? HostingEnvironment.MapPath(settings.AppDataPath) : settings.AppDataPath; }
/// <summary> /// Executes a <see cref="PersistCachedRequestsJob"/>. /// </summary> /// <param name="settings">The settings.</param> private static void ExecutePersistCachedRequestsJob(WarmupCacheSettings settings) { try { new PersistCachedRequestsJob(GetCache("Xrm"), settings).Execute(); } catch (Exception e) { WebEventSource.Log.GenericErrorException(e); } }
/// <summary> /// Configures cache warmup. /// </summary> /// <param name="app">The app.</param> /// <param name="createContext">The context generator.</param> /// <param name="settings">The settings.</param> public static void WarmupCache(this IAppBuilder app, Func <CrmDbContext> createContext, WarmupCacheSettings settings) { var json = CrmJsonConvert.SerializeObject(settings); ADXTrace.Instance.TraceInfo(TraceCategory.Application, json); if (settings.IsEnabled) { if (settings.AsyncWarmupEnabled) { // run warmup job as a scheduled job var registry = new Registry(); registry.Schedule(() => { new WarmupCacheJob(createContext(), settings).Execute(); }) .ToRunOnceIn(settings.AsyncWarmupDelay).Seconds(); JobManager.Initialize(registry); } else { try { // run warmup job synchronously new WarmupCacheJob(createContext(), settings).Execute(); } catch (Exception e) { WebEventSource.Log.GenericErrorException(e); } } // register application shutdown job if (settings.PersistOnAppDisposing) { var properties = new AppProperties(app.Properties); var token = properties.OnAppDisposing; if (token != CancellationToken.None) { token.Register(() => ExecutePersistCachedRequestsJob(settings)); } } // register scheduled job if (settings.PersistOnSchedule) { var registry = new Registry(); registry.Schedule(() => { new PersistCachedRequestsJob(GetCache("Xrm"), settings).Execute(); }) .Reentrant(settings.Reentrant) .ToRunNow().AndEvery(settings.JobInterval).Seconds(); JobManager.Initialize(registry); } } }