Skip to content

Commit

Permalink
Fix typo in the name of the DistributedCacheRateLimitCounterHandler
Browse files Browse the repository at this point in the history
… class (#1969) by @williamscs
  • Loading branch information
williamscs authored Feb 22, 2024
1 parent d54836d commit a9dff7c
Showing 1 changed file with 39 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
using Microsoft.Extensions.Caching.Distributed;
using Newtonsoft.Json;

namespace Ocelot.RateLimit
{
public class DistributedCacheRateLimitCounterHanlder : IRateLimitCounterHandler
{
private readonly IDistributedCache _memoryCache;

public DistributedCacheRateLimitCounterHanlder(IDistributedCache memoryCache)
{
_memoryCache = memoryCache;
}

public void Set(string id, RateLimitCounter counter, TimeSpan expirationTime)
{
_memoryCache.SetString(id, JsonConvert.SerializeObject(counter), new DistributedCacheEntryOptions().SetAbsoluteExpiration(expirationTime));
}

public bool Exists(string id)
{
var stored = _memoryCache.GetString(id);
return !string.IsNullOrEmpty(stored);
}

public RateLimitCounter? Get(string id)
{
var stored = _memoryCache.GetString(id);
if (!string.IsNullOrEmpty(stored))
{
return JsonConvert.DeserializeObject<RateLimitCounter>(stored);
}

return null;
}

public void Remove(string id)
{
_memoryCache.Remove(id);
}
}

namespace Ocelot.RateLimit
{
public class DistributedCacheRateLimitCounterHandler : IRateLimitCounterHandler
{
private readonly IDistributedCache _memoryCache;

public DistributedCacheRateLimitCounterHandler(IDistributedCache memoryCache)
{
_memoryCache = memoryCache;
}

public void Set(string id, RateLimitCounter counter, TimeSpan expirationTime)
{
_memoryCache.SetString(id, JsonConvert.SerializeObject(counter), new DistributedCacheEntryOptions().SetAbsoluteExpiration(expirationTime));
}

public bool Exists(string id)
{
var stored = _memoryCache.GetString(id);
return !string.IsNullOrEmpty(stored);
}

public RateLimitCounter? Get(string id)
{
var stored = _memoryCache.GetString(id);
if (!string.IsNullOrEmpty(stored))
{
return JsonConvert.DeserializeObject<RateLimitCounter>(stored);
}

return null;
}

public void Remove(string id)
{
_memoryCache.Remove(id);
}
}
}

0 comments on commit a9dff7c

Please sign in to comment.