Beispiel #1
0
        internal IObservable <T> InvokePreLoaderWithObservable <T>(string preloaderName, PreLoadParameters parameters)
        {
            var instance = GetPreLoaderInstance <T>(preloaderName);

            string preloadedCacheKey = GetPreLoaderKey(preloaderName, instance, parameters);

            var expiration = instance.GetDataExpiration();


            if (parameters == null)
            {
                parameters = new PreLoadParameters();
            }
            //var observable = instance.GetData(parameters);
            var observable = Observable.Start(() => instance.GetData(parameters), Scheduler.Default)
                             .Merge()
                             .SubscribeOn(new NewThreadScheduler());

            observable.Subscribe(f =>
            {
                var result = new PreLoadResult(expiration, f);
                SetPreLoadedResult(preloadedCacheKey, result);
            });

            return(observable);
        }
Beispiel #2
0
        internal Task InvokePreLoader <T>(string preloaderName, PreLoadParameters parameters)
        {
            var key = GetKey(preloaderName);


            var instance = GetPreLoaderInstance <T>(preloaderName);

            string preloadedCacheKey = GetPreLoaderKey(preloaderName, instance, parameters);

            if (parameters == null)
            {
                parameters = new PreLoadParameters();
            }
            var observable = (IObservable <T>)instance.GetData(parameters);

            var expiration = instance.GetDataExpiration();

            observable.Subscribe(f =>
            {
                var result = new PreLoadResult(expiration, f);
                SetPreLoadedResult(preloadedCacheKey, result);
            });

            //await observable.ForEachAsync(x => Debug.WriteLine(x));
            return(Task.CompletedTask);
        }
Beispiel #3
0
 internal void SetPreLoadedResult(string preloaderName, PreLoadResult result)
 {
     if (result != null)
     {
         preLoaderCachedKeys.Add(preloaderName);
         MemoryCache.Set <object>(preloaderName, result.Data, new MemoryCacheEntryOptions {
             AbsoluteExpirationRelativeToNow = result.AbsoluteExpirationRelativeToNow
         });
     }
 }