Example #1
0
        /// <inheritdoc/>
        public async Task <bool> SetAsync <T>(CoreCachingKey key, T data)
        {
            ThrowExceptionIfFaulty();

            var isOk = !IsEnabled || false;

            if (!isOk)
            {
                var value = LocalStorageService.PutData(key, data);

                isOk = value != null;

                if (isOk && GlobalStorageService != null)
                {
                    if (value is string valueString)
                    {
                        isOk = await GlobalStorageService.PutDataAsync(key, valueString).CoreBaseExtTaskWithCurrentCulture(false);
                    }
                    else
                    {
                        if (value is byte[] valueBytes)
                        {
                            isOk = await GlobalStorageService.PutDataAsync(key, valueBytes).CoreBaseExtTaskWithCurrentCulture(false);
                        }
                        else
                        {
                            isOk = false;
                        }
                    }
                }
            }

            return(isOk);
        }
Example #2
0
        /// <inheritdoc/>
        public bool Set <T>(CoreCachingKey key, T data)
        {
            ThrowExceptionIfFaulty();

            var isOk = !IsEnabled || false;

            if (!isOk && !GlobalStorageHelper.IsFaulty)
            {
                var value = LocalStorageService.PutData(key, data);

                isOk = value != null;

                if (isOk && GlobalStorageService != null)
                {
                    if (value is string valueString)
                    {
                        isOk = GlobalStorageService.PutData(key, valueString);
                    }
                    else
                    {
                        if (value is byte[] valueBytes)
                        {
                            isOk = GlobalStorageService.PutData(key, valueBytes);
                        }
                        else
                        {
                            isOk = false;
                        }
                    }
                }
            }

            return(isOk);
        }
Example #3
0
        /// <inheritdoc/>
        public T Get <T>(CoreCachingKey key)
        {
            ThrowExceptionIfFaulty();

            T result = default;

            if (IsEnabled && !GlobalStorageHelper.IsFaulty)
            {
                result = LocalStorageService.GetData <T>(key);

                if (result != null)
                {
                    return(result);
                }

                if (GlobalStorageService != null)
                {
                    result = GlobalStorageService.GetData <T>(key);
                }
            }

            return(result);
        }
Example #4
0
        /// <inheritdoc/>
        public async Task <T> GetAsync <T>(CoreCachingKey key)
        {
            ThrowExceptionIfFaulty();

            T result = default;

            if (IsEnabled)
            {
                result = LocalStorageService.GetData <T>(key);

                if (result != null)
                {
                    return(result);
                }

                if (GlobalStorageService != null)
                {
                    result = await GlobalStorageService.GetDataAsync <T>(key).CoreBaseExtTaskWithCurrentCulture(false);
                }
            }

            return(result);
        }