Welcome to mirror list, hosted at ThFree Co, Russian Federation.

7.0-rc1_System.Threading.RateLimiting.md « Microsoft.AspNetCore.App « rc1 « api-diff « preview « 7.0 « release-notes - github.com/dotnet/core.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 24de4da479e180871d31f36798c022c1da5684cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# System.Threading.RateLimiting

``` diff
+namespace System.Threading.RateLimiting {
+    public sealed class ConcurrencyLimiter : RateLimiter {
+        public ConcurrencyLimiter(ConcurrencyLimiterOptions options);
+        public override TimeSpan? IdleDuration { get; }
+        protected override ValueTask<RateLimitLease> AcquireAsyncCore(int permitCount, CancellationToken cancellationToken = default(CancellationToken));
+        protected override RateLimitLease AttemptAcquireCore(int permitCount);
+        protected override void Dispose(bool disposing);
+        protected override ValueTask DisposeAsyncCore();
+        public override RateLimiterStatistics? GetStatistics();
+    }
+    public sealed class ConcurrencyLimiterOptions {
+        public ConcurrencyLimiterOptions();
+        public int PermitLimit { get; set; }
+        public int QueueLimit { get; set; }
+        public QueueProcessingOrder QueueProcessingOrder { get; set; }
+    }
+    public sealed class FixedWindowRateLimiter : ReplenishingRateLimiter {
+        public FixedWindowRateLimiter(FixedWindowRateLimiterOptions options);
+        public override TimeSpan? IdleDuration { get; }
+        public override bool IsAutoReplenishing { get; }
+        public override TimeSpan ReplenishmentPeriod { get; }
+        protected override ValueTask<RateLimitLease> AcquireAsyncCore(int requestCount, CancellationToken cancellationToken = default(CancellationToken));
+        protected override RateLimitLease AttemptAcquireCore(int requestCount);
+        protected override void Dispose(bool disposing);
+        protected override ValueTask DisposeAsyncCore();
+        public override RateLimiterStatistics? GetStatistics();
+        public override bool TryReplenish();
+    }
+    public sealed class FixedWindowRateLimiterOptions {
+        public FixedWindowRateLimiterOptions();
+        public bool AutoReplenishment { get; set; }
+        public int PermitLimit { get; set; }
+        public int QueueLimit { get; set; }
+        public QueueProcessingOrder QueueProcessingOrder { get; set; }
+        public TimeSpan Window { get; set; }
+    }
+    public static class MetadataName {
+        public static MetadataName<string> ReasonPhrase { get; }
+        public static MetadataName<TimeSpan> RetryAfter { get; }
+        public static MetadataName<T> Create<T>(string name);
+    }
+    public sealed class MetadataName<T> : IEquatable<MetadataName<T>> {
+        public MetadataName(string name);
+        public string Name { get; }
+        public override bool Equals([NotNullWhenAttribute(true)] object? obj);
+        public bool Equals(MetadataName<T>? other);
+        public override int GetHashCode();
+        public static bool operator ==(MetadataName<T> left, MetadataName<T> right);
+        public static bool operator !=(MetadataName<T> left, MetadataName<T> right);
+        public override string ToString();
+    }
+    public static class PartitionedRateLimiter {
+        public static PartitionedRateLimiter<TResource> Create<TResource, TPartitionKey>(Func<TResource, RateLimitPartition<TPartitionKey>> partitioner, IEqualityComparer<TPartitionKey>? equalityComparer = null);
+        public static PartitionedRateLimiter<TResource> CreateChained<TResource>(params PartitionedRateLimiter<TResource>[] limiters);
+    }
+    public abstract class PartitionedRateLimiter<TResource> : IAsyncDisposable, IDisposable {
+        protected PartitionedRateLimiter();
+        public ValueTask<RateLimitLease> AcquireAsync(TResource resource, int permitCount = 1, CancellationToken cancellationToken = default(CancellationToken));
+        protected abstract ValueTask<RateLimitLease> AcquireAsyncCore(TResource resource, int permitCount, CancellationToken cancellationToken);
+        public RateLimitLease AttemptAcquire(TResource resource, int permitCount = 1);
+        protected abstract RateLimitLease AttemptAcquireCore(TResource resource, int permitCount);
+        public void Dispose();
+        protected virtual void Dispose(bool disposing);
+        public ValueTask DisposeAsync();
+        protected virtual ValueTask DisposeAsyncCore();
+        public abstract RateLimiterStatistics? GetStatistics(TResource resource);
+        public PartitionedRateLimiter<TOuter> WithTranslatedKey<TOuter>(Func<TOuter, TResource> keyAdapter, bool leaveOpen);
+    }
+    public enum QueueProcessingOrder {
+        NewestFirst = 1,
+        OldestFirst = 0,
+    }
+    public abstract class RateLimiter : IAsyncDisposable, IDisposable {
+        protected RateLimiter();
+        public abstract TimeSpan? IdleDuration { get; }
+        public ValueTask<RateLimitLease> AcquireAsync(int permitCount = 1, CancellationToken cancellationToken = default(CancellationToken));
+        protected abstract ValueTask<RateLimitLease> AcquireAsyncCore(int permitCount, CancellationToken cancellationToken);
+        public RateLimitLease AttemptAcquire(int permitCount = 1);
+        protected abstract RateLimitLease AttemptAcquireCore(int permitCount);
+        public void Dispose();
+        protected virtual void Dispose(bool disposing);
+        public ValueTask DisposeAsync();
+        protected virtual ValueTask DisposeAsyncCore();
+        public abstract RateLimiterStatistics? GetStatistics();
+    }
+    public class RateLimiterStatistics {
+        public RateLimiterStatistics();
+        public long CurrentAvailablePermits { get; set; }
+        public long CurrentQueuedCount { get; set; }
+        public long TotalFailedLeases { get; set; }
+        public long TotalSuccessfulLeases { get; set; }
+    }
+    public abstract class RateLimitLease : IDisposable {
+        protected RateLimitLease();
+        public abstract bool IsAcquired { get; }
+        public abstract IEnumerable<string> MetadataNames { get; }
+        public void Dispose();
+        protected virtual void Dispose(bool disposing);
+        public virtual IEnumerable<KeyValuePair<string, object?>> GetAllMetadata();
+        public abstract bool TryGetMetadata(string metadataName, out object? metadata);
+        public bool TryGetMetadata<T>(MetadataName<T> metadataName, [MaybeNullAttribute] out T metadata);
+    }
+    public static class RateLimitPartition {
+        public static RateLimitPartition<TKey> Get<TKey>(TKey partitionKey, Func<TKey, RateLimiter> factory);
+        public static RateLimitPartition<TKey> GetConcurrencyLimiter<TKey>(TKey partitionKey, Func<TKey, ConcurrencyLimiterOptions> factory);
+        public static RateLimitPartition<TKey> GetFixedWindowLimiter<TKey>(TKey partitionKey, Func<TKey, FixedWindowRateLimiterOptions> factory);
+        public static RateLimitPartition<TKey> GetNoLimiter<TKey>(TKey partitionKey);
+        public static RateLimitPartition<TKey> GetSlidingWindowLimiter<TKey>(TKey partitionKey, Func<TKey, SlidingWindowRateLimiterOptions> factory);
+        public static RateLimitPartition<TKey> GetTokenBucketLimiter<TKey>(TKey partitionKey, Func<TKey, TokenBucketRateLimiterOptions> factory);
+    }
+    public struct RateLimitPartition<TKey> {
+        public RateLimitPartition(TKey partitionKey, Func<TKey, RateLimiter> factory);
+        public Func<TKey, RateLimiter> Factory { get; }
+        public TKey PartitionKey { get; }
+    }
+    public abstract class ReplenishingRateLimiter : RateLimiter {
+        protected ReplenishingRateLimiter();
+        public abstract bool IsAutoReplenishing { get; }
+        public abstract TimeSpan ReplenishmentPeriod { get; }
+        public abstract bool TryReplenish();
+    }
+    public sealed class SlidingWindowRateLimiter : ReplenishingRateLimiter {
+        public SlidingWindowRateLimiter(SlidingWindowRateLimiterOptions options);
+        public override TimeSpan? IdleDuration { get; }
+        public override bool IsAutoReplenishing { get; }
+        public override TimeSpan ReplenishmentPeriod { get; }
+        protected override ValueTask<RateLimitLease> AcquireAsyncCore(int requestCount, CancellationToken cancellationToken = default(CancellationToken));
+        protected override RateLimitLease AttemptAcquireCore(int requestCount);
+        protected override void Dispose(bool disposing);
+        protected override ValueTask DisposeAsyncCore();
+        public override RateLimiterStatistics? GetStatistics();
+        public override bool TryReplenish();
+    }
+    public sealed class SlidingWindowRateLimiterOptions {
+        public SlidingWindowRateLimiterOptions();
+        public bool AutoReplenishment { get; set; }
+        public int PermitLimit { get; set; }
+        public int QueueLimit { get; set; }
+        public QueueProcessingOrder QueueProcessingOrder { get; set; }
+        public int SegmentsPerWindow { get; set; }
+        public TimeSpan Window { get; set; }
+    }
+    public sealed class TokenBucketRateLimiter : ReplenishingRateLimiter {
+        public TokenBucketRateLimiter(TokenBucketRateLimiterOptions options);
+        public override TimeSpan? IdleDuration { get; }
+        public override bool IsAutoReplenishing { get; }
+        public override TimeSpan ReplenishmentPeriod { get; }
+        protected override ValueTask<RateLimitLease> AcquireAsyncCore(int tokenCount, CancellationToken cancellationToken = default(CancellationToken));
+        protected override RateLimitLease AttemptAcquireCore(int tokenCount);
+        protected override void Dispose(bool disposing);
+        protected override ValueTask DisposeAsyncCore();
+        public override RateLimiterStatistics? GetStatistics();
+        public override bool TryReplenish();
+    }
+    public sealed class TokenBucketRateLimiterOptions {
+        public TokenBucketRateLimiterOptions();
+        public bool AutoReplenishment { get; set; }
+        public int QueueLimit { get; set; }
+        public QueueProcessingOrder QueueProcessingOrder { get; set; }
+        public TimeSpan ReplenishmentPeriod { get; set; }
+        public int TokenLimit { get; set; }
+        public int TokensPerPeriod { get; set; }
+    }
+}
```