Example #1
0
            public bool Success(Tval val, TimeSpan outdated_ttl, out ProCacheEntry <Tval> entry)
            {
                entry = _entry;

                if (_completion is null)
                {
                    entry.Reset(val, outdated_ttl);
                    return(true);
                }

                _completion.SetResult(val);
                entry.Reset(val, null);

                return(false);
            }
Example #2
0
            public bool Empty(TimeSpan outdated_ttl, out ProCacheEntry <Tval> entry)
            {
                entry = _entry;

                if (_completion is null)
                {
                    entry.Reset(outdated_ttl);
                    return(true);
                }

                entry.Reset(null);
                _completion.SetResult(default(Tval));

                return(false);
            }
Example #3
0
        private async ValueTask <Tval> UpdateAsync(Tkey key, ProCacheEntry <Tval> entry, object state, CancellationToken cancellation)
        {
            try
            {
                var res = await _get(key, state, cancellation).ConfigureAwait(false);

                entry.Reset(res, _outdateTtl);
                _cache.Set(key, entry, _expireTtl);
                return(res);
            }
            catch
            {
                entry.Reset();
                throw;
            }
        }
Example #4
0
            public bool Error(Exception ex)
            {
                if (_completion is null)
                {
                    _entry.Reset();
                    return(false);
                }

                _completion.SetException(ex);
                return(true);
            }
Example #5
0
            public bool Success(Tval val, TimeSpan outdated_ttl, out ProCacheEntry <Tval> entry)
            {
                switch (_state)
                {
                case ResultState.Add:
                    ((TaskCompletionSource <(bool, Tval)>)_completion).SetResult((true, val));
                    entry = null;
                    return(false);

                case ResultState.Outdate:
                    entry = (ProCacheEntry <Tval>)_completion;
                    entry.Reset(val, outdated_ttl);
                    return(true);
                }

                throw new NotImplementedException();
            }