/// <summary> /// Registers a callback to be invoked when a new IndexSearcher is being initialized. /// This method allows an IndexSearcher to be "warmed up" by executing one or more /// queries before the instance becomes visible on other threads. /// /// While callbacks are being executed, other threads will continue to use the previous /// instance of IndexSearcher if this is not the first instance being initialized. /// /// If this is the first instance, other threads will block until all callbacks complete. /// </summary> public void RegisterCacheWarmingCallback <T>(Action <IQueryable <T> > callback, ObjectLookup <T> lookup, IDocumentMapper <T> documentMapper) { context.SearcherLoading += (s, e) => { Log.Trace(m => m("Invoking cache warming callback " + lookup)); var warmupContext = new WarmUpContext(context, e.IndexSearcher); var queryable = CreateQueryable(lookup, warmupContext, documentMapper); callback(queryable); Log.Trace(m => m("Callback {0} completed.", lookup)); }; }
/// <summary> /// Same as <see cref="RegisterCacheWarmingCallback{T}(System.Action{System.Linq.IQueryable{T}})"/> /// but allows client to provide factory method for creating new instances of <typeparamref name="T"/>. /// </summary> public void RegisterCacheWarmingCallback <T>(Action <IQueryable <T> > callback, Func <T> factory) { context.SearcherLoading += (s, e) => { Log.Trace(m => m("Invoking cache warming callback " + factory)); var warmupContext = new WarmUpContext(context, e.IndexSearcher); var queryable = CreateQueryable(factory, warmupContext); callback(queryable); Log.Trace(m => m("Callback {0} completed.", factory)); }; }
public MigrationHostedService(ILogger <MigrationHostedService> logger, WarmUpContext context) { this._logger = logger; this._context = context; }