public void SetMany(ReadOnlySpan <KeyValuePair <TKey, TValue> > values, TimeSpan timeToLive) { CheckDisposed(); var nowTicks = TicksHelper.GetTicks64(); foreach (var value in values) { SetImpl(value.Key, value.Value, timeToLive, nowTicks); } }
public void Mark(string key) { var now = TicksHelper.GetTicks64(); if (!_dictionary.TryAdd(key, now)) { return; } _queue.Enqueue(new KeyValuePair <string, long>(key, now)); }
public int GetMany(ReadOnlySpan <TKey> keys, Span <KeyValuePair <TKey, TValue> > destination) { CheckDisposed(); if (destination.Length < keys.Length) { throw Errors.LocalCache_DestinationArrayTooSmall(nameof(destination)); } var countFound = 0; var nowTicks = TicksHelper.GetTicks64(); foreach (var key in keys) { if (TryGetImpl(key, nowTicks, out var value)) { destination[countFound++] = new KeyValuePair <TKey, TValue>(key, value); } } return(countFound); }
public void Set(TKey key, TValue value, TimeSpan timeToLive) { CheckDisposed(); SetImpl(key, value, timeToLive, TicksHelper.GetTicks64()); }
public bool TryGet(TKey key, out TValue value) { CheckDisposed(); return(TryGetImpl(key, TicksHelper.GetTicks64(), out value)); }
private bool IsRecent(long timestamp) { var age = TicksHelper.GetTicks64() - timestamp; return(age < _recentWindow); }