예제 #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);
        }
예제 #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);
        }
예제 #3
0
        public bool TryGetPreLoadedData <T>(string name, out T value, PreLoadParameters parameters = null)
        {
            T   valueInternal;
            var result = PreLoaderServiceCore.Instance.TryGetPreLoadedData <T>(name, parameters, out valueInternal);

            value = valueInternal;
            return(result);
        }
예제 #4
0
        internal T GetCachedPreLoadedData <T>(string preloaderName, PreLoadParameters parameters)
        {
            var instance = GetPreLoaderInstance <T>(preloaderName);

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

            var cachedData = MemoryCache.Get <T>(preloadedCacheKey);

            return(cachedData);
        }
예제 #5
0
        internal bool TryGetPreLoadedData <T>(string name, PreLoadParameters parameters, out T value)
        {
            value = default(T);
            var cachedData = GetCachedPreLoadedData <T>(name, parameters);

            if (cachedData != null)
            {
                value = cachedData;
                return(true);
            }
            return(false);
        }
예제 #6
0
        private string GetPreLoaderKey <T>(string preloaderName, IPreLoader <T> instance, PreLoadParameters parameters)
        {
            if (parameters == null)
            {
                parameters = new PreLoadParameters();
            }
            string preloadedCacheKey = preloaderName;

            if (instance is IPreLoaderKey instanceKey)
            {
                preloadedCacheKey = $"{preloaderName}:{instanceKey.GetKey(parameters)}";
            }

            return(preloadedCacheKey);
        }
예제 #7
0
 public void InvokePreLoader <T>(string preloaderName, PreLoadParameters parameters = null)
 {
     var observable = PreLoaderServiceCore.Instance.InvokePreLoaderWithObservable <T>(preloaderName, parameters);
 }
예제 #8
0
 public T GetPreLoadedData <T>(string name, PreLoadParameters parameters = null)
 {
     return(PreLoaderServiceCore.Instance.GetCachedPreLoadedData <T>(name, parameters));
 }