Skip to content

Commit 9248b82

Browse files
committed
Assembly name fix in rate limit
1 parent 1ee3c90 commit 9248b82

File tree

3 files changed

+7
-18
lines changed

3 files changed

+7
-18
lines changed

src/DistributedCache/DistributedCache.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<PackageReadmeFile>Readme.md</PackageReadmeFile>
99
<Authors>Pandatech</Authors>
1010
<Copyright>MIT</Copyright>
11-
<Version>1.2.2</Version>
11+
<Version>1.2.3</Version>
1212
<PackageId>Pandatech.DistributedCache</PackageId>
1313
<Title>Pandatech Distributed Cache</Title>
1414
<PackageTags>Pandatech, library, redis, distributed locks, cache</PackageTags>

src/DistributedCache/Services/Implementations/RedisRateLimitService.cs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ public class RedisRateLimitService(
1818
private readonly IRedisDatabase _redisDatabase = redisClient.GetDefaultDatabase();
1919
private readonly CacheConfigurationOptions _config = options.Value;
2020

21+
private readonly string _moduleName = Assembly.GetCallingAssembly()
22+
.GetName()
23+
.Name!;
24+
2125
public async ValueTask<RateLimitState> RateLimitAsync(RateLimitConfiguration rateLimitConfiguration,
2226
CancellationToken cancellationToken = default)
2327
{
24-
var assemblyName = GetCallingAssemblyName();
25-
2628
var key = _config.KeyPrefixForIsolation == KeyPrefix.None
2729
? KeyFormatHelper.GetPrefixedKey(rateLimitConfiguration.GetKey())
28-
: KeyFormatHelper.GetPrefixedKey(rateLimitConfiguration.GetKey(), assemblyName);
30+
: KeyFormatHelper.GetPrefixedKey(rateLimitConfiguration.GetKey(), _moduleName);
2931

3032

3133
var lockValue = Guid.NewGuid()
@@ -94,18 +96,4 @@ public async ValueTask<RateLimitState> RateLimitAsync(RateLimitConfiguration rat
9496
await lockService.ReleaseLockAsync(key, lockValue);
9597
}
9698
}
97-
98-
private static string GetCallingAssemblyName()
99-
{
100-
var stackTrace = new StackTrace();
101-
foreach (var frame in stackTrace.GetFrames())
102-
{
103-
var method = frame.GetMethod();
104-
if (method != null && method.DeclaringType != typeof(RedisRateLimitService))
105-
{
106-
return method.DeclaringType!.Assembly.GetName().Name!;
107-
}
108-
}
109-
return Assembly.GetExecutingAssembly().GetName().Name!;
110-
}
11199
}

test/DistributedCache.Demo/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
builder.Services.AddScoped<CacheTestsService>();
1212
builder.Services.AddScoped<SendSmsService>();
1313

14+
1415
builder.AddDistributedCache(o =>
1516
{
1617
o.RedisConnectionString = "localhost:6379";

0 commit comments

Comments
 (0)