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);
        }