-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix/remove limit on popular words (#113)
* Replace in-memory caching with Redis caching. * Solve cycling problem for the next 100+ years
- Loading branch information
Showing
10 changed files
with
60 additions
and
56 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
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,6 +1,6 @@ | ||
namespace Core.Cache | ||
{ | ||
public interface IRecentIndexesCache : ICache<string> | ||
public interface IRecentIndexesCache : ISetBasedCache<string> | ||
{ | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Core.Cache | ||
{ | ||
public interface ISimpleCache | ||
{ | ||
Task SetAsync<T>(string key, T value, TimeSpan? expiry = null); | ||
Task<T?> GetAsync<T>(string key); | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Ardalis.GuardClauses; | ||
using Core.Cache; | ||
using Infrastructure.Configuration; | ||
using Microsoft.Extensions.Options; | ||
using StackExchange.Redis; | ||
namespace Infrastructure.Redis | ||
{ | ||
public class SimpleRedisCache(IConnectionMultiplexer connectionMultiplexer, IOptions<RedisConfig> redisConfig) : | ||
RedisCache(connectionMultiplexer, redisConfig), ISimpleCache | ||
{ | ||
public async Task<T?> GetAsync<T>(string key) | ||
{ | ||
RedisValue theValue = await _cache.StringGetAsync(key); | ||
|
||
return theValue.IsNullOrEmpty ? default : ConvertToType<T>(theValue); | ||
} | ||
|
||
private static T ConvertToType<T>(RedisValue value) | ||
{ | ||
if(typeof(T) == typeof(DateTimeOffset)) | ||
{ | ||
return (T)(object)DateTimeOffset.Parse(value.ToString()); | ||
} | ||
return (T)Convert.ChangeType(value.ToString(), typeof(T)); | ||
} | ||
|
||
public async Task SetAsync<T>(string key, T value, TimeSpan? expiry = null) | ||
{ | ||
await _cache.StringSetAsync(key, Guard.Against.Null(value)!.ToString(), expiry); | ||
} | ||
} | ||
} |
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