-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix typo in the name of the
DistributedCacheRateLimitCounterHandler
…
… class (#1969) by @williamscs
- Loading branch information
1 parent
d54836d
commit a9dff7c
Showing
1 changed file
with
39 additions
and
39 deletions.
There are no files selected for viewing
78 changes: 39 additions & 39 deletions
78
...istributedCacheRateLimitCounterHanlder.cs → ...istributedCacheRateLimitCounterHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |